[英]MySQL Double Order
Is there a better way to write 有没有更好的写作方式
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
(The code above is suppose to find all the users with a certain zipcode, and order them by the last_activity timestamp) (上面的代码假设找到具有特定邮政编码的所有用户,并按last_activity时间戳排序)
Also, is there anyway to sort it by last_activity and gender? 另外,还有以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
Just add gender: 只需添加性别:
ORDER BY users.last_activity DESC, users.gender
Note that ordering by the second one (in this case gender
) will only happen if two users have the same last_activity
value. 请注意,只有当两个用户具有相同的
last_activity
值时,才会按第二个(在本例中为gender
)进行排序。 Consider it a "tie-breaker" ordering. 将其视为“打破平局”的订单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.