我想只选择具有最大优先级的id,以及item_id为1001的下表(table1)。
表1
id | plan_id | item_id | plan_item_bundle_id | precedence
-----+---------+---------+---------------------+------------
401 | | 1001 | | -1
402 | | 1001 | | -1
我该怎么办?感谢
我不在乎优先级是否相同,任何人都会这样做。 感谢
答案 0 :(得分:0)
select id from table1
group by id, prededence
having precedence = max(precedence )
Limit 0, 1
答案 1 :(得分:0)
尝试此查询
select id from table1 where precedence =(select max(precedence) from table1)
答案 2 :(得分:0)
你可以尝试:
SELECT id FROM table1
WHERE precedence = MAX(precedence)
AND item_id = 1001
LIMIT 1
或
SELECT id FROM table1
WHERE precedence = (SELECT MAX(precedence) FROM table1)
AND item_id = 1001
LIMIT 1