1、功能需求
统计一张表中不同状态的数据总和,然后把2个字段放到一行中显示,方便用ORM框架映射;
比如:
统计某个人所有订单的总和、统计某个人所有未支付订单的总和,将这两个字段组装成一个SQL,结果类似
select orders,todo_orders from xxx
2、代码思路
分别使用count(1)
统计出2个不同逻辑的数据总和,然后使用SQL语句定义成临时表的方式组装SQL,如下:
select orders,todo_orders from
(select count(1) as orders from t_fixorder where fixm_id='9526') b,
(select count(1) as todo_orders from t_fixorder where fixm_id='9526'} and status=3) c