0
以下查詢:MySQL的分組結果
SELECT COUNT(*) AS count, items.category, customers.sector
FROM customers
LEFT JOIN items ON items.customer_id = customers.id
GROUP BY items.category, customers.sector
ORDER BY customers.sector ASC
給了我這樣的結果:
| count | category | sector |
|-------|-----------------------|--------------|
| 3 | A-Frames & Trolleys | Automotive |
| 4 | Suction Mounts | Automotive |
| 1 | Hand Cups | Automotive |
| 103 | Glazing Tools | Construction |
| 2 | A-Frames & Trolleys | Construction |
| 2 | Suction Mounts | Construction |
|_______|_______________________|______________|
我想部門欄是唯一的,以示與最大計數 例如類別:
| count | category | sector |
|-------|-----------------------|--------------|
| 4 | Suction Mounts | Automotive |
| 103 | Glazing Tools | Construction |
|_______|_______________________|______________|
謝謝
所以,你想要的'MAX(COUNT())'每個'sector'? – Kermit
是的,這就是我所追求的 –