2019-02-27
閱讀量:
732
如何查詢(xún)某字段相同數(shù)據(jù)出現(xiàn)次數(shù)大于3的信息?
如何查詢(xún)某字段相同數(shù)據(jù)出現(xiàn)次數(shù)大于3的信息?
select num ,count(num) as new_num
from xxy_logs
group by num
where new_num>3;
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where new_num>3' at line 4
答:where 關(guān)鍵字不能和group by 一起使用的(主要是不能放在group by 之后,不能作用于聚合后的數(shù)據(jù)),這時(shí)我們可以使用hiving語(yǔ)句來(lái)過(guò)濾返回的記錄集,可以按照下面的方式k來(lái)寫(xiě)。
select num ,count(num) as new_num
from xxy_logs
group by num
HAVING new_num>3;






評(píng)論(0)


暫無(wú)數(shù)據(jù)
CDA考試動(dòng)態(tài)
CDA報(bào)考指南
推薦帖子
0條評(píng)論
0條評(píng)論
0條評(píng)論
1條評(píng)論