请在 SQL Server PIVOT Table 中帮助我。我得到了如下所示的输出。现在我想要在每个日期行下的单独列中分配待处理和编码待处理的总数。
select ScanDate, filestatus, COUNT(filestatus) as filecount from ScanLog
where FileSource = 'ebridge'
group by filestatus, ScanDate
scandate filestatus filecount
2013-08-01 Allocation Pending 8
2013-08-01 Coding Pending 1
2013-08-02 Allocation Pending 4
2013-08-02 Coding Pending 1
2013-08-03 Allocation Pending 4
2013-08-04 Allocation Pending 18
2013-08-04 Coding Pending 3
2013-08-05 Allocation Pending 6
我使用了以下代码,但由于“scandate”不是有效字段而出现错误。请指导我。
select [scandate] from ScanLog
pivot (count(scandate)
for filestatus in ([allocation pending],[coding pending])) as A
where FileSource = 'ebridge'