订单表根据商品ID分类,同时根据商品状态获取不同的值

日期:2019-08-08 浏览:151次

mysql语句:


1
SELECT o.*,g.name,count(o.status>1 or null) as goods_count_ed,count(o.status=1 or null) as goods_count_ing,sum(o.price) as total_price FROM `test_order` `o` LEFT JOIN `test_goods` `g` ON `g`.`id`=`o`.`goods_id` GROUP BY `o`.`goods_id
查询打印结果: tp5mysql链式语句:

1
2
3
4
5
6
7
$data = Db::name('order')
->alias('o')
->join('goods g','g.id=o.goods_id','LEFT')
->field('o.*,g.name,count(o.status>1 or null) as goods_count_ed,count(o.status=1 or null) as goods_count_ing,sum(o.price) as total_price ')
->group('o.goods_id')
->select();
halt($data);

没有评论

发表评论