一起来看看这个例子:
$sql = 'select distinct(ontopid),gb.id as id,f.id as fid,g.id as gid,g.*,gb.*,f.* from pk_groupbuy gb
left join pk_ontop as o on o.ontopid=gb.id
left join pk_goods g on gb.goodsid=g.id and g.status=2 and g.invalid>UNIX_TIMESTAMP()
left join pk_fastgroupbuy f on gb.fastgroupbuyid=f.id
where gb.id in ('.$arr_str.') and (gb.status="2" or gb.status="3")
and gb.endtime>UNIX_TIMESTAMP() and gb.starttime<UNIX_TIMESTAMP()
group by onid limit $start,$num";
return TableSystem::query($sql);
变量说明:$arr_str是一个由pk_groupbuy中主键 id组成的一个数组,经过explode函数得到的字符串,$start,$num分别是查询的开始记录数,和要查询的记录数。
问题说明:pk_ontop表中ontopid在不能记录中有重复现象
比如:我只需要查询出来pk_ontop中当天置顶的ontopid,即商品id,不需要其他的商品信息,查询出来的有ontopid就算有重复现象,这时我可以通过去除数组重复元素