Mysql
 sql >> Datenbank >  >> RDS >> Mysql

SELECT Zeilen mit minimaler Anzahl(*)

Versuchen Sie, dieses Skript als Muster zu verwenden -

-- find minimum count
SELECT MIN(cnt) INTO @min FROM (SELECT COUNT(*) cnt FROM voting GROUP BY candidate) t;

-- show records with minimum count
SELECT * FROM voting t1
  JOIN (SELECT id FROM voting GROUP BY candidate HAVING COUNT(*) = @min) t2
    ON t1.candidate = t2.candidate;