我想根据月份和我的查询对总和进行分组,如下所示
SELECT terminal_name,
sum(case when month(sales_timestamp) = 1 then nc_deposit else 0 end) as
jan_amount,
count(case when month(sales_timestamp) = 1 then nc_deposit else 0 end) as
jan_count
FROM dbfastshosted.dbo.fh_mf_new_card_logs cl
INNER JOIN dbfastshosted.dbo.fh_sales_map m on cl.nc_log_id = m.nc_log_id
INNER JOIN dbfastshosted.dbo.fh_sales_logs sl on m.sales_id = sl.sales_id
INNER JOIN dbfastsconfigdataref.dbo.cdf_terminal_user_account h on
cl.created_user_id = h.terminal_user_id
INNER JOIN dbfastsconfigdataref.dbo.cdf_terminal t on h.terminal_id =
t.terminal_id
INNER JOIN dbfastsconfigdataref.dbo.cdf_cuid c on cl.cu_id = c.cu_id
INNER JOIN dbfastshosted.dbo.fh_mf_top_up_logs tu on tu.tu_log_id =
m.tu_log_id
WHERE YEAR(nc_timestamp)='2017'
and top_up_status = 1
and (cr_log_id is null or cr_log_id = 0)
GROUP BY terminal_name
terminal_name jan_amount jan_count .... dec_amount dec_count
---------------------------------------------------------------------------
terminal A 1000 10 50000 500
但是,输出是错误的。由于总和值是正确的,但计数功能不能正常工作。你能告诉我们这些吗?谢谢!
总和 - 卡和卡的总销售额 count - 卡片总数