![](/img/trans.png)
[英]how to fetch the records based on value is exist in the column or not in mysql?
[英]How to fetch the records based on the no of occurences of a value in certain field in MySQL?
我想通過事件獲取名為ppno的字段的記錄。 即。
(GIVE ME RECORDS WHERE PPNO repeating same 5 times)
像這樣
Name PPNO
John TNi89873
Smith TNi89873
Mark TNi89873
Joe TNi89873
Cane TNi89873
Mary OCSV
Mark OCSV
Don OCSV
Crook OCSV
Mike OCSV
像這樣
select * from tbl where ppno in
(select ppno from tbl group by ppno having count(ppno) > 4)
SELECT T1.Name,
T1.PPNO
FROM table AS T1
WHERE T1.PPNO IN (SELECT T2.PPNO
FROM Table AS T2
WHERE T2.PPNO = T1.PPNO
HAVING COUNT(T2.PPNO) = 5)
ORDER BY T1.PPNO,
T1.Name
像這樣的東西(未經測試)
SELECT Name, PPNO FROM Table WHERE PPNO IN
(SELECT PPNO FROM Table GROUP BY PPNO HAVING Count(PPNO)=5)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.