[英]MySQL Double Order
有沒有更好的寫作方式
SELECT users.id FROM `users`,`profiles` WHERE users.id = profiles.id &&
profiles.zipcode = '$zipcode' && users.id != '1' && users.id != '2'
&& profiles.picture != '' ORDER BY users.last_activity DESC LIMIT 0,11
(上面的代碼假設找到具有特定郵政編碼的所有用戶,並按last_activity時間戳排序)
另外,還有以last_activity和性別對它進行排序嗎?
SELECT users.id
FROM `users`
JOIN `profiles` ON users.id = profiles.id
WHERE profiles.zipcode = '$zipcode'
AND users.id NOT IN (1,2)
AND profiles.picture != ''
ORDER BY users.last_activity DESC, users.gender
LIMIT 0,11
只需添加性別:
ORDER BY users.last_activity DESC, users.gender
請注意,只有當兩個用戶具有相同的last_activity
值時,才會按第二個(在本例中為gender
)進行排序。 將其視為“打破平局”的訂單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.