Mysql SQL中的ORDER BY不工作
我有一个SQL查询:Mysql SQL中的ORDER BY不工作,mysql,sql,Mysql,Sql,我有一个SQL查询: SELECT conversations_messages.conversation_id, MAX(conversations_messages.message_date) AS 'conversation_last_reply', MAX(conversations_messages.message_date) > conversations_users.last_view AS 'conversation_unre
SELECT
conversations_messages.conversation_id,
MAX(conversations_messages.message_date) AS 'conversation_last_reply',
MAX(conversations_messages.message_date) > conversations_users.last_view AS 'conversation_unread'
FROM
conversations_messages
LEFT JOIN conversations ON conversations_messages.message_id=conversations.id
INNER JOIN conversations_users ON conversations_messages.conversation_id=conversations_users.conversation_id
WHERE
conversations_users.user_id = $user_id AND
conversations_users.deleted=0
GROUP BY
conversations_messages.message_id
ORDER BY
'conversation_last_reply' DESC
查询按我的要求运行良好,但只有ORDER BY的最后一行不起作用,它没有按照我的要求进行排序
而唯一不起作用的是最后一行-由。。。
我试图将其更改为ASC和DESC,但它没有响应。。。
*顺便说一下,我试图排序的字段是一个整数
有人知道问题出在哪里
谢谢。您是否尝试过按对话订购邮件。邮件日期?您是否尝试过按对话订购邮件。邮件日期?尝试一下
ORDER BY conversation_last_reply
而不是
ORDER BY 'conversation_last_reply'
当前版本按常量字符串排序,因此根本不排序。试试看
ORDER BY conversation_last_reply
而不是
ORDER BY 'conversation_last_reply'
当前版本按常量字符串排序,因此它根本不排序。您的订单周围有引号
ORDER BY
'conversation_last_reply' DESC
----^-----------------------^------ = bad
你应该把它改成
ORDER BY
conversation_last_reply DESC
或者使用反勾号
ORDER BY
`conversation_last_reply` DESC
按字符串排序时,没有排序,因为每行的字符串值始终相同:您的订单周围有引号
ORDER BY
'conversation_last_reply' DESC
----^-----------------------^------ = bad
你应该把它改成
ORDER BY
conversation_last_reply DESC
或者使用反勾号
ORDER BY
`conversation_last_reply` DESC
按字符串排序时,没有排序,因为每行的字符串值始终相同:尝试不添加引号orderby
ORDER BY conversation_last_reply
尝试不添加引号orderby
ORDER BY conversation_last_reply
不需要报价。按列名排序,而不是按字符串文字排序!不需要报价。按列名排序,而不是按字符串文字排序!该死的差点就赢了我!gj+我的第一句话:该死的,差点就赢了我!gj+我的1:todd不起作用,因为OP想按MAXdate排序,而不仅仅是日期:是的,但我必须按特定的数学函数MAXtodd排序,这不起作用,因为OP想按MAXdate排序,而不仅仅是日期:是的,但我必须按特定的数学函数排序MAX@DavidAlexandrovich你没有我必须接受我的答案,但请不要忘记将答案标记为已接受!:这让其他人想继续回答问题:@DavidAlexandrovich你不必接受我的答案,但请不要忘记将答案标记为已接受!:这让其他人想继续回答问题: