![](/img/trans.png)
[英]How can I return a random row for each section in a MySQL data set that has non-unique values
[英]How can I count the non-unique combinations of values in MySQL?
我有一個表,其中包含一些舊數據,我懷疑這些舊數據可能有些混亂。 這是一個多對多聯接表。
LIST_MEMBERSHIPS
----------------
list_id
address_id
我想運行一個查詢,該查詢將計算每個list_id
- address_id
對的出現次數,並顯示從最高到最低出現次數中的每一個的出現次數。
我知道必須涉及COUNT()
和GROUP BY
,對嗎?
select list_id, address_id, count(*) as count
from LIST_MEMBERSHIPS
group by 1, 2
order by 3 desc
您可能會發現添加有用
having count > 1
select count(*), list_id, address_id
from list_membership
group by list_id, address_id
order by count(*) desc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.