假設我有一個表格,其中包含電子郵件、topic_id 列。一封郵件可以多次對應一個topic_id。我想根據電子郵件和 topic_id 申請分組。但我無法計算有多少行組合在一起。例子。
email topic_id
abc@gmail.com 1
abc@gmail.com 1
abc@gmail.com 1
abc@gmail.com 2
xyz@gmail.com 1
xyz@gmail.com 1
xyz@gmail.com 1
輸出應給出:
email topic_id count
abc@gmail.com 1 3
abc@gmail.com 2 1
xyz@gmail.com 1 3
uj5u.com熱心網友回復:
簡單的分組和計數?:
select email,topic_id, count(*)
from tablename
group by email,topic_id
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/483029.html
標籤:sql PostgreSQL
