我有以下脚本(SQL Server 2016),它正在逐行输出(我可以用 Excel 计算 - 作弊)但我真的很想总结每个“取消”、“firstfill”、“笔芯”等,但我一辈子都无法弄清楚这个 Count / Group by ..
非常感谢任何帮助。抱歉格式问题,无法弄清楚。
Select rx.Storeid, Case When Cast(canceldate as Date) is not null then 'Cancel' When OrigRxNum = RxNum and Status=1 and Canceldate is null then 'FirstFill'
When OrigRxNum <> RxNum and Status=1 and Canceldate is null then 'Refill'
When Cast(Canceldate as date) is null and Status=3 then 'Unfill'
--When OrigRxNum = RxNum and Status=2 then 'Unfill Cancel'
Else 'Other'
End RxStatus
From Rx
Where Storeid =575 and Cast(TransactionDate as DATE) >= '02-28-2023' and Cast(TransactionDate as DATE) <= '03-28-2023'
and status in(1,2,3)