mysql if

Posted zfzf1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql if相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

mysql初学,mysql修改,mysql查找,mysql删除,mysql基本命令

mysql(设置/更改mysql密码,连接MySQL,MySQL常用命令,MySQL两种引擎区别)

MySQL教程

MySQL

MySQL

有什么学习MySQL的好教程吗?