我为一家电信公司工作,每个月我都会在表格中加载一个数字列表,下面的代码显示了他们与之交谈的部门,并按导入日期排序。
目前我必须为每个导入日期添加一个新的count(case)
语句,是否有一种方法可以运行它以便它获取新日期并将它们放在列中以便我不必去添加每次加载新数据时都会生成一个新的count(case)语句。
sel
dept
,count(case when import_date = '2013-03-26' then import_date
else null end) as "WE 26/03"
,count(case when import_date = '2013-07-25' then import_date
else null end) as "WE 25/07"
,count(case when import_date = '2013-08-22' then import_date
else null end) as "WE 22/08"
,count(case when import_date = '2013-09-09' then import_date
else null end) as "WE 09/09"
from IPSHARE.HRData
inner join IPSHARE .RMO_CHURN_TRIGGER
on msn = svc_no
group by dept;
输出如下
dept | WE 26/03 | WE 25/07 |WE 22/08 |WE 09/09
Mobile Retention| 57,433 | 26,185 |24,686 |23,593
Mobile Tech | 21,036 | 11,999 |7,566 |7,429
FS Low Risk | 17,988 | 8,074 |7,879 |7,917
General | 17,068 | 10,111 |5,226 |4,549
Bus Mob Retent | 16,737 | 16,477 |396 |736
答案 0 :(得分:1)
SQL92具有EXTRACT函数
其用途为select EXTRACT(DAY FROM import_date)
所以我想你可以做到
select 'WE' + EXTRACT(DAY FROM import_date) + '/' + EXTRACT(MONTH FROM import_date) from IPSHARE.HRData