Thinkphp 超长sql语句编写

SELECT g.gname,sum(s.sp_number) as total FROM luofang_goods_snapshot AS s right JOIN luofang_goods g on s.sp_gid = g.gid WHERE ( `jid` = '1' ) AND ( gstatus <> -1 AND gtype=0 ) GROUP BY g.gid ORDER BY total desc LIMIT 3

这是一个简单的例子:

对应的tp的代码编写如下

$arr = M('goods_snapshot')->alias('AS s')->join('__GOODS__ g on s.sp_gid = g.gid','right')->field('g.gname,sum(s.sp_number) as total')->where($condition)->where($string)->group('g.gid')->order('total desc')->limit('3')->select();

 

对已生成的结果集进行排序

初次写可能会生疏 写多了就ok啦

我在想你 I miss you qingqing。 Do you know?

你可能感兴趣的:(Thinkphp 超长sql语句编写)