Mysql根据数组列表查找最大列值

时间:2013-08-07 09:18:45

标签: mysql

您好我有以下mysql表

id  item_name user_id wishlist item_url id_category cost
30     kiko    76        1                 70         10
31     test1   76        1                 70         20
32     test12  76        1                 68,67      30

我如何获得最高成本项目。这意味着我需要基于类别ID的最高成本项目。enter image description here

我尝试使用SELECT MAX(cost),id FROM item_tbl WHERE (FIND_IN_SET('68','70,68,67'))没有返回正确的输出,认为它提供了30个max(cost)。谢谢

1 个答案:

答案 0 :(得分:1)

这可能会为您提供所需的输出。

SELECT ID_CATEGORY, MAX(COST) FROM ITEM_TBL
GROUP BY ID_CATEGORY;