这个查询有什么问题?:
SELECT
'posts'.'post_id' AS 'id',
'posts'.'post_title' AS 'title',
LEFT('posts','post_body', 512) AS 'preview',
'posts'.'post_user' AS 'user',
DATE_FORMAT('posts'.'post_date', '%d/%m/%Y %H:%i:%s') AS 'DATE',
'comments'.'total_comments',
DATE_FORMAT('comments'.'last_comment', '%d/%m/%Y %H:%i:%s') AS 'last_comment'
FROM 'posts'
LEFT JOIN (
SELECT
'post_id',
COUNT('comment_id') AS 'total_comments',
MAX('comment_date') AS 'last_comment'
FROM 'comments'
GROUP BY 'post_id'
) AS 'comments'
ON 'posts'.'post_id' = 'comments'.'post_id'
ORDER BY 'posts'.'post_date' DESC
我得到:
#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 '.'post_id' AS 'id', 'posts'.'post_title' AS 'title', LEFT('posts','p' at line 附近使用的正确语法2