-1
我有以下查询我知道是不正确的语法计数特定属性
SELECT Vender as Carrier,
count(IsPup WHERE IsPup = 1) as PU,
count(IsFull WHERE IsFull = 1) as FU,
count(*) as NUM, count(IsPup)/2 + Count(IsFull) as FTE
FROM Trailers WHERE Completed = 0 group by Vender order by NUM;
特别是count(IsPup WHERE IsPup = 1)
是错误的,我已经搜查各种短语,如“如何计算在SQL行的多个属性”等 并试图在同一查询的其他操作一样count(IsPup) as PU, count(IsFull) as FU
我有语法正确的查询
SELECT Vender as Carrier,
count(IsPup) as PU,
count(IsFull) as FU,
count(*) as NUM,
count(IsPup)/2 + Count(IsFull) as FTE
FROM Trailers WHERE Completed = 0 group by Vender order by NUM
其中运行,但PU,FU和NUM始终是相同的值...
我试图得到一个表像下面
| Carrier | PU | FU | NUM | FTE |
--------------------------------------------
| Vender1 | 2 | 1 | 3 | 2 |
| Vender2 | 0 | 4 | 4 | 4 |
| TOTAL | 2 | 5 | 7 | 6 |
的拖车表有IsPup和IsFull作为BIT
类型,所以它们是真或假(0或1) 我认为这个查询会很简单,觉得我缺少一些明显的东西
如何获得每个单独的属性和总数的计数? 标记的重复问题与底部总数的格式不匹配。
“IsPup”和“IsFull”的潜在价值是什么?看起来你可以使用SUM(CASE)语句。然后在'Group By'后面使用'With Rollup' –
[基于SQL Server中的条件计数]的可能重复(https://stackoverflow.com/questions/3455201/count-based-on-condition-in-sql - 服务器) –
你想谷歌什么是“基于条件的sql服务器几个计数” –