mysql 一次查询,返回多个count统计结果

发布时间:2020-01-13作者:小灵龙点击:145

问题描述:
   在一个表中有多个条件,其中两个条件是共同的,另外两个条件是不同,一条sql语句返回多个统计结果。按照时间分组。
解决办法:


$sql="  select count(pay_terminal=0 and pay_type=1 or null) as appwei,

                count(pay_terminal=0 and pay_type=2 or null) as appzhi,

                count(pay_terminal=0 and pay_type=3 or null) as appyu,

                count(pay_terminal=2 and pay_type=1 or null) as xiaowei,

                count(pay_terminal=2 and pay_type=3 or null) as xiaoyu,

                count(pay_terminal=3 and pay_type=1 or null) as saowei,

                count(pay_terminal=3 and pay_type=2 or null) as saozhi,

                count(pay_terminal=3 and pay_type=9 or null) as saoyi,

                FROM_UNIXTIME(confirm_date,'%m/%d') as x_date

                from gcwxcx_order 

                where

                order_state=2 and

                is_type=3 and

                confirm_date >= ".$t_date1." and

                confirm_date < ".$t_date2."

                group by FROM_UNIXTIME(confirm_date,'%Y-%m-%d')";

        $count=Db::query($sql);

标签: