繁体   English   中英

MySQL错误每组Reatest-n

[英]MySQL error Reatest-n-per-group

帮我!

       SELECT ma_forum.*, ma_forum_cat.*

        FROM ma_forum, ma_forum_cat

        JOIN ma_forum_comentarios ON ma_forum_comentarios.not_id = ma_forum.not_id

        GROUP BY ma_forum.not_id

        WHERE ma_forum.notcat_id=ma_forum_cat.notcat_id AND ma_forum.notcat_id='".$notcat_id."' 

        AND ma_forum.not_status='Ativo'

        ORDER BY MAX(ma_forum_comentarios.comnot_data) DESC

“您的SQL语法有错误;请在第9行的'WHERE ma_forum.notcat_id = ma_forum_cat.notcat_id AND ma_forum.notcat_id ='1''附近使用与MySQL服务器版本相对应的手册,以使用正确的语法。”

您的查询顺序错误; GROUP BY应该在WHERE之后和ORDER BY之前:

SELECT ma_forum.*, ma_forum_cat.*
FROM ma_forum, ma_forum_cat
JOIN ma_forum_comentarios ON ma_forum_comentarios.not_id = ma_forum.not_id
WHERE ma_forum.notcat_id=ma_forum_cat.notcat_id AND ma_forum.notcat_id='".$notcat_id."' 
AND ma_forum.not_status='Ativo'
GROUP BY ma_forum.not_id
ORDER BY MAX(ma_forum_comentarios.comnot_data) DESC

我不知道您使用的是哪个数据库,但这是指向MySQL的SELECT语法的链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM