我有一张这样的桌子
DRID ReceivedUser ReceivedDate JobOrder Warranty Service DeliveredUser DeliveredDate Active
1 abc 3/7/2017 78330 O 2 xyz 3/9/2017 N
2 abc 3/9/2017 93045 O 2 abc 3/9/2017 N
3 xyz 3/9/2017 10620 O 2 xyz 3/9/2017 N
4 xyz 3/9/2017 11393 O 2 Y
5 pqr 3/9/2017 12101 O 2 xyz 3/9/2017 N
6 xyz 3/9/2017 12545 I 2 pqr 3/9/2017 N
7 pqr 3/9/2017 13512 O 2 xyz 3/9/2017 N
8 xyz 3/9/2017 13642 I 2 xyz 3/9/2017 N
9 xyz 3/9/2017 15190 O 2 abc 3/9/2017 N
我想尝试选择这样的
Received Warranty Outwarranty Total
abc 0 2 2
xyz 2 3 5
pqr 0 2 2
但是我得到了这样的结果
Received Warranty Outwarranty Total
xyz 2 0 2
xyz 0 3 3
abc 0 2 2
pqr 0 2 2
我的代码
select ReceivedUser,Case WHEN Warranty='i' THEN COUNT(JobOrder) Else 0 END As Warranty,Case WHEN
Warranty='O' THEN Count(JobOrder) ELSE 0 End AS OutWarranty,Count(JobOrder) As Total
from DailyReceipt
where CAST(ReceivedDate AS date)=GETDATE()
Group By ReceivedUser,Warranty
按照今天的日期选择数据。
答案 0 :(得分:1)