檢索AA組數字。如果我有表:MySQL查詢到從各組
------------------
| Provider | ID |
------------------
| X | 125 |
------------------
| X | 133 |
------------------
| X | 342 |
------------------
| X | 327 |
------------------
| Y | 123 |
------------------
| Y | 853 |
------------------
| Y | 123 |
------------------
| Z | 853 |
------------------
| Z | 533 |
------------------
| Z | 174 |
------------------
我想從每個供應商X和Y得到2個隨機項(忽略Z)生產
X id
X id
Y id
Y id
我試過幾個查詢包括
select id, provider from tableName a where (SELECT COUNT(*) FROM tableName b where b.provider = a.provider) = 2;
任何想法?