28,390
社区成员
发帖
与我相关
我的任务
分享
select goods.goodsid,goods.goodsname,sortedgoodscomments.allcomments from goods,
(select goodsid,SUM(commentclass) as allcomments from goodscomments group by goodsid) as sortedgoodscomments
where goods.goodsid=sortedgoodscomments.goodsid order by sortedgoodscomments.allcomments
select * ,(
select sum( commentclass )
from 你的这张表名 as b
where a.产品的id = b.goodsid
) as sortcol
from goods as a order by sortcol desc
试试看WITH t1
AS (SELECT goodsid,
Sum(CommentClass) num
FROM table_name
GROUP BY goodsid)
SELECT a.ID,
a.GoodsID,
a.CommentClass
FROM table_name a
LEFT JOIN t1 b ON a.goodsid = b.goodsid
ORDER BY b.num desc