当前位置:Gxlcms > 数据库问题 > mysql if

mysql if

时间:2021-07-01 10:21:17 帮助过:2人阅读

select t.site_id,
sum(a)中通,
sum(b)圆通,
sum(c)申通,
sum(d)汇通,
sum(e)韵达

from

(
select t.site_id,
if(courier_company_id=24,num,0)a,
if(courier_company_id=11,num,0)b,
if(courier_company_id=13,num,0)c,
if(courier_company_id=27,num,0)d,
if(courier_company_id=12,num,0)e
FROM

( SELECT
site_id,
t.courier_company_id,
count(1) num
FROM
express_order_stor t
WHERE
t.status = 7
AND t.create_time >=‘2019-03-20‘
AND t.create_time <‘2019-03-31‘
and t.site_id in(
21573,
21422,
19737,
30937,
33905,
33195,
33899,
32959,
31851,
32955,
30871,
27827,
20228,
16470,
30505,
5314,
4636,
27829,
33833,
16489,
30923,
11536,
6071,
38459,
28501,
16615,
16892,
22636,
16677,
30501,
32683,
33901,
33897,
19746,
30483,
30503,
19749,
20226,
5316,
5258,
5320,
6036,
31797,
36083,
19688,
30921,
19716,
21625,
19710,
4670,
16897,
11188,
30867,
39081,
38935,
32903,
30935,
30925,
21489,
20275,
20163,
12384,
5298,
5276,
5249

)
group by t.site_id,t.courier_company_id
)t
)t
group by t.site_id

mysql if

标签:order   rom   express   creat   sum   HERE   exp   group by   any   

人气教程排行