我的表格如下:
content_id | contact_count
1 23
2 4
3 89
我想从表格的最后25行中选择具有最高contact_count的content_id。
我尝试过许多不同的事情,例如:
select content_id from research_products_content
where contact_count=(select max(contact_count)
from research_products_content order by rating_total_id desc limit 25)
order by rating_total_id desc limit 1
答案 0 :(得分:0)
由于列号相同,因此使用UNION
select content_id from research_products_content
where contact_count=(select max(contact_count)
from research_products_content order by rating_total_id desc limit 25)
UNION
select content_id from research_products_content
where contact_count=(select max(contact_count)
from research_products_content order by rating_total_id desc limit 1
您可能希望沿途实施缓存
答案 1 :(得分:0)
在您的示例中,{<1}}应用后结果(max,即单行)被选中。试试这个:
limit 25