我认为这对你们这些人来说很简单,但我有点难以弄清楚如何做到这一点。我试过但没有得到结果所以想在这里咨询每一个。
这里我有三列:state,store,laptop_brand 我想过滤掉有多少商店有HP< 3(按国家分组)。
我对此的想法是这样的:
SELECT state, count(laptop_brand)
FROM sample_survey
WHERE count(select store from sample_survey where laptop_brand = "HP") <3 group by state
但我无法实现。 sample_survey 附加的pic片段数据供您参考。
感谢您提出任何建议。
答案 0 :(得分:0)
请试试这个:
SELECT state, store, count(laptop_brand) as total_laptop
FROM sample_survey
WHERE laptop_brand = "HP"
GROUP BY state, store
HAVING count(laptop_brand)<3
答案 1 :(得分:0)
在像这样的有条款中的第二个编码
SELECT state, count(laptop_brand) as cnt
FROM sample_survey
WHERE laptop_brand = "HP" group by state HAVING cnt <3