1
许多2个多我有表/记录是这样的:ORDER BY子句中的MySQL
Table: COMMENTS
---------------------------------------------
COMMENT_ID | CONTENT | CREATE_DATE
---------------------------------------------
1 | Content 1 | 2016-09-01
2 | Content 2 | 2016-09-02
3 | Content 3 | 2016-09-03
4 | Reply to Content 2 | 2016-09-04
5 | Reply to Content 1 | 2016-09-05
6 | Reply to Content 2 | 2016-09-03
Table: REPLY_COMMENTS
---------------------------------
COMMENT_ID | REPLY_TO_COMMENT_ID
---------------------------------
4 | 2
5 | 1
6 | 2
而且我想表明这样的顺序记录:
---------------------------------------------
COMMENT_ID | CONTENT | CREATE_DATE
---------------------------------------------
1 | Content 1 | 2016-09-01
5 | Reply to Content 1 | 2016-09-05
2 | Content 2 | 2016-09-02
6 | Reply to Content 2 | 2016-09-03
4 | Reply to Content 2 | 2016-09-04
3 | Content 3 | 2016-09-03
所以'回复“内容应该在父母的内容下 - 但回复内容也应该由CREATE_DATE定购。
基本上,我想放在一起:内容和CREATE_DATE的顺序回复。
我写这样的查询:
SELECT comment.*
FROM COMMENTS comment
LEFT JOIN REPLY_COMMENTS reply_comment ON reply_comment.COMMENT_ID = comment.COMMENT_ID
ORDER BY (SOMETHING SHOULD BE HERE), comment.CREATE_DATE ASC
我不能用我目前的知识写order by子句 - 请帮我(我使用MySQL)。
我只希望使用的COMMENTS.CREATE_DATE
场 - 不想使用COMMENT_ID
领域,因为它的主键(它甚至有可能?)。