带有计数和限制问题的子查询

时间:2013-11-29 18:25:22

标签: php mysql subquery

我有一个子查询,它按如下方式计算track_id

SELECT track_id, COUNT( * ) 
FROM  track_comments 
GROUP BY track_id
ORDER BY COUNT( * ) DESC 
LIMIT 10

我想要做的是根据从此查询收到的track_id运行查询。怎么办呢?

1 个答案:

答案 0 :(得分:0)

select * from your_table
where track_id in 
(
    SELECT track_id
    FROM track_comments 
    GROUP BY track_id 
    ORDER BY COUNT( * ) DESC 
    LIMIT 10
)