我有一个表,其中有一个 boolean 字段
扫描。
我想在 C# WinForm 中显示已完成和未决扫描的计数。
我在 SQL 中使用存储过程。
select count(1),sum(pages),count(distinct custId) from TableA where scanning=0 --Pending
select count(1),sum(pages),count(distinct custId) from TableA where scanning=1 --Done
我需要在 SQL 中创建两个存储过程,还是有办法从单个存储过程中获取结果。
最佳答案
SELECT
PendingCnt = COUNT_BIG(CASE WHEN scanning = 0 THEN 1 END),
PendingSum = ISNULL(SUM(CASE WHEN scanning = 0 THEN pages END), 0),
PendingCustID = COUNT_BIG(DISTINCT CASE WHEN scanning = 0 THEN custId END),
DoneCnt = COUNT_BIG(CASE WHEN scanning = 1 THEN 1 END),
DoneSum = ISNULL(SUM(CASE WHEN scanning = 1 THEN pages END), 0),
DoneCustID = COUNT_BIG(DISTINCT CASE WHEN scanning = 1 THEN custId END)
FROM TableA
关于c# - 从两个 where 条件返回 SQL 值以在 C# 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35768847/