使用count(1)確認presto、SQL、HIVE查詢沒有重複數據

例如我們錨定student_id

select count(1),
count(distinct student_id) ----注意distinct 的重要使用
from
abc.table_student;

不一致那麼就有重複值,會出現一對多,一個id多條信息

或者:
select student_id,count(1) from abc.table_student
group by student_id
having count(1)>=2;

count(1)的作用,就是統計在分組中,每一組對應的行數或項數。效率和作用和count(*)相同。
Count()中的表達式是否爲NULL,如果爲NULL則不計數,而非NULL則會計數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章