一般情况下,我们会遇到查询当status=1的时候,统计总金额,当status=2的时候,统计总金额,那么一般可能就是两条语句:
SELECT SUM(fee) from hbmy_park_recode where `status` = 1
SELECT SUM(fee) from hbmy_park_recode where `status` = 2
如果想一条语句查询出来的话,怎么办呢?
不多说,代码如下:
SELECT SUM(if((`status` = 1),fee,0)),SUM(if((`status` = 2),fee,0)) from hbmy_park_recode