【发布时间】:2015-02-28 15:21:12
【问题描述】:
我有以下 mysql 查询
select registration,
sum(`week01`) as `2015/01`,
sum(`week02`) as `2015/02`
from (select registration,
case when concat(YEAR(act_del_time_arrive),'/',week(act_del_time_arrive))='2015/01' then round(costed_amount,0) else '' end 'week01' ,
case when concat(YEAR(act_del_time_arrive),'/',week(act_del_time_arrive))='2015/02' then round(costed_amount,0) else '' end 'week02'
from vw_tekwani_schedule_main
where act_del_time_arrive between '2015-01-04' and '2015-02-28'
and haulier_id = 4 and registration is not null
group by registration, date(act_del_time_arrive)
order by registration) as t group by registration
产生以下结果
reg 2015/01 2015/02
'A10' , '0' , '0'
'A2' , '0' , '0'
'A3' , '0' , '0'
'A4' , '0' , '0'
'A5' , '0' , '0'
'A6' , '0' , '0'
'A7' , '0' , '0'
'A8' , '0' , '0'
'A9' , '0' , '0'
我迫切需要找出如何过滤掉在 2015/01 和 2015/02 具有零值的行。
所以理论上我不会得到从这个查询返回的结果
【问题讨论】:
-
据我所知,你所有的行在那边的值都为零?
-
WHERE '2015/02' != 0 ...不行吗? -
我已经尝试过您建议 thomas 的过滤器,但它仍然返回零值行;(