*修訂,但仍然沒有解決... *MySQL的 - JOIN或UNION - 不知道這,也許兩者(第二部分)
我想將數據從兩個文件合併,但我無法表達這種排序。我想對來自第一個文件的CREATED日期和來自第二個文件的SHARED_DATE進行排序,如果它存在並且它更大。
file 1 : NODE
fields: CREATED, CHANGED
file 2 : SHARE_CONTENT
fields: SHARED_DATE , NODE (foreign key)
...
SELECT n.created, s.shared_date,
(CASE WHEN s.shared_date <> NULL
then s.shared_date
else n.created
END)
as lastshare
FROM node as n LEFT JOIN share_content as s on (s.nid=n.nid)
ORDER BY lastshare DESC
另一種可能性..
SELECT n.created, s.shared_date,
FROM node as n LEFT JOIN share_content as s on (s.nid=n.nid)
ORDER BY MAX(n.created, s.shared_date) DESC
除了MySQL的似乎並不像Max(A,B)
'MAX(..)'只能用'集團by' – rauschen