0

我想显示所有项目,首先显示项目最多的特殊项目,并且它们必须按特殊分组。

[id] [specials_id] [item]
1         1        bread
2         2        bread
3         2        eggs
4         1        peanut
5         2        macaroni
6         3        peanut
7         2        juice

结果应该是这样的:

    2 bread
    2 eggs
    2 macaroni
    2 juice
    1 bread
    1 peanut
    3 peanut

我试过这个,但它只返回其中一个:

   SELECT COUNT(*) AS `Rows`, item, special_id 
   FROM my_table 
   GROUP BY special_id 
   ORDER BY   `Rows` DESC

有人可以帮助我吗?

4

1 回答 1

0

使用此查询:

SELECT COUNT( * ) AS Rows1, spl_id, name
FROM `new`
GROUP BY `spl_id` , `name`
ORDER BY   `Rows1` DESC
于 2012-04-16T12:56:10.603 回答