例子:
SELECT
FROM_UNIXTIME (created, "%Y-%m-%d") as created_date,
count(*) as `all`,
sum(
if(order_status = 1, 1, 0)
) as new,
sum(
if(order_status = 2, 1, 0)
) as approved,
sum(
if (order_status = 3, 1, 0)
) as picked
FROM
sale_order
group by
created_date
讲解:可以把if()里面的看成三元表达式
正确的选择第二个统计 不正确统计第三个
只统计数量可以不写后两个参数,统计总量比如金额的必须写