0

我有 2 张桌子:

故事 ID (int), CONTENT (文本)

投票 ID (int), TYPE (int, 1 or 0), ID_STORY (int)

如何获取查询以返回按票数排序的前 10 个故事 (=1) desc。?我希望能够打印前 10 个故事内容。

我已经尝试了很多这里提供的类似问题的解决方案,但我无法做到正确......

4

2 回答 2

2
SELECT *, count(votes) AS vcount
  FROM stories s, votes v
 WHERE s.id=v.id_story
   AND v.type=1
 GROUP BY v.id_story
 ORDER BY vcount DESC
于 2010-12-21T17:58:00.420 回答
0
SELECT 
    storyid,content 
FROM 
    stories 
WHERE 
    storyid IN (
        SELECT 
            storyid,count(votes) AS count 
        FROM 
            stories LEFT JOIN votes ON stories.storyid=votes.storyid 
        WHERE 
            type=1 
            GROUP BY votes.storyid 
            ORDER BY count DESC
)
于 2010-12-21T18:04:47.033 回答