簡體   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