我有这张桌子
noArticle QuantiteCommandee
10 20
20 9
40 4
50 2
60
70 8
80
81
90 1
95 3
我想要计算有多少文章在量化中的数量超过5且少于2
我现在拥有的:
/
SELECT COUNT ( case when QuantiteCommandee > 5 THEN 1 ELSE 0 END) AS PLUSQUE5,
COUNT ( case when QuantiteCommandee < 2 THEN 1 ELSE 0 END ) AS PLUSPETITQUE2
From (SELECT Article.noArticle, SUM (quantite) AS QuantiteCommandee
FROM Article
LEFT JOIN LigneCommande ON Article.noArticle = LigneCommande.noArticle
GROUP By ( Article.noArticle))
/
它让我回头
PLUSQUE2 PLUSQUE5
10 10
它似乎看不到我的状况&gt; 5和&lt; 2
编辑:从表中你看到的是顶部的表格我不知道我能给你的信息是什么?
已解决:删除ELSE PART
答案 0 :(得分:0)
请试试这个 -
SELECT
COUNT ( case when QuantiteCommandee > 5 THEN 1 END) AS PLUSQUE5,
COUNT ( case when QuantiteCommandee < 2 THEN 1 END ) AS PLUSPETITQUE2
From (
SELECT
Article.noArticle, SUM (quantite) AS QuantiteCommandee
FROM Article
LEFT JOIN LigneCommande ON Article.noArticle = LigneCommande.noArticle
GROUP By (Article.noArticle)
)
答案 1 :(得分:0)
使用此查询
select count(case when QuantiteCommandee>5 then 1 end) count_greaterthan_5,
count(case when QuantiteCommandee<2 then 1 end) count_lessthan_2
from sandeep24feb_3;