我正在查看添加日期范围到下面的查询。任何帮助都会很棒,谢谢你。SUM子类别合并为一个
select (case when col2 in ('Commercial', 'Non-commercial') then 'Commercial'
when col2 in ('OEM', 'CA-OEM') then 'OEM'
else 'col2'
end),
sum(col4) as col4
from t
group by (case when col2 in ('Commercial', 'Non-commercial') then 'Commercial'
when col2 in ('OEM', 'CA-OEM') then 'OEM'
else 'col2'
end);
日期以SQL
SELECT Customer_type,TRX_DATE (FORMAT 'YYYY-MM') (CHAR(7)) AS BATCH_DATE_MONTH
WHERE CAST(TRX_DATE AS DATE FORMAT 'mm/dd/yyyy') >= '02-01-2016'
Group BY 1,2
ORDER BY 1
Customer_Type BATCH_DATE_MONTH Number_Invoices Billed_Amount
1 Commercial-Non-OEM 2016-02 48 382458.92
2 Commercial- Non-OEM 2016-05 77 7646263.67
5 Non-OEM 2016-05 81 11841927.23
6 Non-OEM 2016-02 25 1630832.81
9 OEM 2016-04 68 280264011.01
10 OEM 2016-03 74 277606302.23
13 CA-OEM 2016-03 23 947248.13
14 CA-OEM 2016-05 17 420363.61
17 US-OEM 2016-04 35 4627887.87
18 US-OEM 2016-03 40 6450226.49
19 US-OEM 2016-02 21 3267732.17
请标记与您正在使用的数据库你的问题。 –