ARTICLES
SUBSTRING_INDEX(str,delim,count)
2015-07-23 21:30:110字号:
  1. {pc:get sql="select a.id,a.title,a.url,a.catid,b.hitsid,b.catid,b.views from v9_shop a left join v9_hits b on a.id=substring_index(b.`hitsid`, '-', -1) where a.status=99 and b.catid in ($arrchildid) order by b.monthviews desc" num="10" cache="3600"}

商品排行,用到了 substring_index ,两个表关联,hitsid字段存储格式不规范,用substring_index截取过滤。
SUBSTRING_INDEX(str,delim,count) 返回字符串 str 中在第 count 个出现的分隔符 delim 之前的子串。如果 count 是一个正数,返回从最后的(从左边开始计数)分隔符到左边所有字符。如果 count 是负数,返回从最后的(从右边开始计数)分隔符到右边所有字符。