应用多个限制

时间:2012-04-28 23:22:14

标签: mysql

我的表格如下:

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

2 个答案:

答案 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