0
我想在90算分數,但這個結束了。如果我的數據是如何計算分數超過90 SQL
100
45
90
100
它應該顯示3總行
select g.score as score
,count(case when g.score>=90 then 1 else 0 end) over() as passed
from grades g
計數,而是它顯示4
我想在90算分數,但這個結束了。如果我的數據是如何計算分數超過90 SQL
100
45
90
100
它應該顯示3總行
select g.score as score
,count(case when g.score>=90 then 1 else 0 end) over() as passed
from grades g
計數,而是它顯示4
你要麼刪除ELSE
一部分,所以默認爲NULL和COUNT
犯規次數NULL
select g.score as score
,count(case when g.score>=90 then 1 end) over() as passed
from grades g
或更改COUNT
爲SUM
select g.score as score
,SUM(case when g.score>=90 then 1 else 0 end) over() as passed
from grades g
只需在SUM
編輯COUNT
。 COUNT
計數非空值,所以它甚至計數0; SUM
只會'計數'非零值
謝謝大聲笑不,我沒有喝水,我gu it着它 – user1854438