I want to know about count
function in SQL Server with a where
clause
我想通過where子句了解SQL Server中的count函數
Something like...
select
sum(sales) <-- all sales
, count(ranking) <-- under 100 ranking
from
A_chart
So I think...
所以我認為...
select
sum(sales)
, count(select * from A_chart where ranking <= 100)
where
A_chart.
A_chart
data for example
例如A_chart數據
ranking sales
1 100
2 50
3 30
4 5
Then, I want to know all sales SUM, but ranking under 2.
然后,我想知道所有銷售商的SUM,但排名低於2。
So, is this right?
那么,這是對的嗎?
select
sum(all sales), count(ranking < 2)
where A_chart.
Please teach me. Thanks.
請教我。謝謝。
1
This is what you are looking for
這就是你要找的
select
sum(sales) <-- all sales
,count(case when ranking < 100 then 1 end) <-- under 100 ranking
from
A_chart
0
Your question is unclear but I think this is what you want:
你的問題不清楚,但我認為這就是你想要的:
SELECT
SUM(Sales) as [Sum of Sales],
COUNT(*) as [Count of Rankings]
FROM
A_chart
WHERE
ranking < 2 -- Change this to ranking < 100 for the first part of your question
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/07/17/57003750242979faeae30754a5fdf217.html。