全新的子查詢,我試圖從表showcase
通過他們的評論數(按降序)並不知道如何訂購帖子。按次數(*)子查詢
SELECT *
FROM showcase
ORDER BY
(select count(*)
from comments)
DESC
全新的子查詢,我試圖從表showcase
通過他們的評論數(按降序)並不知道如何訂購帖子。按次數(*)子查詢
SELECT *
FROM showcase
ORDER BY
(select count(*)
from comments)
DESC
我們需要沿着使用組數:
select s.postId, count(c.commentid) as comments
from showcase s join comment c on s.postId = c.postId
group by s.postId
order by comments desc
如果你只需要身份證,group by和每個組
select showcase.id
from showcase left join comments on comments.item_id = showcase.id
group by showcase.id
order by count(showcase.id) desc
,你可以指望行嘗試一個更適合查詢的連接查詢。
SELECT `showcase`.*, count(`comments`.`item_id`) as item_id FROM `showcase`
LEFT JOIN `comments`
ON `showcase`.`id`, `comments`.`item_id`
ORDER BY item_id DESC
讓我知道是工作或沒有。
您的查詢中展示和評論之間沒有關係。 –
更好得到表structute –
評論具有'item_id',這是'id'在陳列櫃 – frosty