复杂顺序与条款
我在尝试从MySQL查询订购结果时遇到了问题。
该表包含用户信息,尤其是:
- user_status(integer)
- user_verified(boolean)
- last_login(date)
该订单按子句应将用户分组为6个主要组,并且在每个组中以last_login desc订购它们。
因此,我试图获得(在伪代码中):
first show users: user_status = 1 AND user_verified = true, last_login DESC
then: user_status = 1 AND user_verified = false, last_login DESC
then: user_status = 2 AND user_verified = true, last_login DESC
then: user_status = 2 AND user_verified = false, last_login DESC
then: user_status = 0 AND user_verified = true, last_login DESC
then: user_status = 0 AND user_verified = false, last_login DESC
我遇到问题,将其放在一条连贯的顺序中,以便对任何帮助都表示感谢!
I'm having problems trying to order the results from a MySQL query.
The table contains user information, notably:
- user_status (an integer)
- user_verified (boolean)
- last_login (date)
The ORDER BY clause should group users into 6 main groups and within each group order them by the last_login DESC.
Thus I'm trying to get (in pseudo code):
first show users: user_status = 1 AND user_verified = true, last_login DESC
then: user_status = 1 AND user_verified = false, last_login DESC
then: user_status = 2 AND user_verified = true, last_login DESC
then: user_status = 2 AND user_verified = false, last_login DESC
then: user_status = 0 AND user_verified = true, last_login DESC
then: user_status = 0 AND user_verified = false, last_login DESC
I'm having problems putting this together into a coherent ORDER BY clause so any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在子句中使用
顺序中的布尔表达式,因为它们被评估为
0 0 for1
true
或。。
false -functions.html#function_field“ rel =“ nofollow noreferrer”>
field()
函数:You can use boolean expressions in the
ORDER BY
clause, because they are evaluated as1
fortrue
or0
forfalse
.In your case you can simplify your requirement to:
or:
or with
FIELD()
function: