解决 联表查询 group by 之后 order by desc 不支持排序问题

来源:互联网 发布:jscript和javascript 编辑:程序博客网 时间:2024/05/02 00:21

支持排序的代码SELECT * , count( mid ) AS mid
FROM (
SELECT A.mid, A.title, A.sortrank, A.pubdate
FROM `acms_archives` AS A
LEFT JOIN `acms_arctype` AS B ON A.typeid = B.id
WHERE B.topid =18
AND A.arcrank =0
AND A.sortrank = A.pubdate
AND A.pubdate >0
ORDER BY pubdate DESC
) AS z
GROUP BY z.mid
ORDER BY z.pubdate DESC
LIMIT 0 , 7

原代码

SELECT A.title,A.sortrank,A.pubdate FROM `acms_archives` as A left join `acms_arctype` as B ON A.typeid = B.id where B.topid=18 and A.arcrank=0  and A.sortrank = A.pubdate  and A.pubdate > 0 group by A.mid order by A.pubdate desc limit 0,7