SQL ORDER BY(顺序) [英] SQL ORDER BY (sequence)

查看:35
本文介绍了SQL ORDER BY(顺序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 sql 语句,我想要ORDER BY 一个特定的序列.

I have a sql statement which I would want to ORDER BY a specific sequence.

SELECT * FROM UserDB ORDER BY [Role]

我怎样才能使带到我的 GridView 表中的数据从管理员列在顶部,然后是用户和来宾?

How can I make it such that the data brought to my GridView table is listed from Admin on the top, follow by User and Guests?

推荐答案

所以您想按 Admin/User/Guest 订购?

尝试类似:

SELECT * 
FROM UserDB 
ORDER BY
  CASE Role WHEN 'Admin' THEN 0 
            WHEN 'User' THEN 1
            WHEN 'Guest' THEN 2
  END

这对你有用吗?

另一种选择是在您的 Role 表中添加(或添加)一列 Sequence,这样您就可以在表本身中定义序列 - 然后只是添加到ORDER BY Role.Sequence.

Another option would be to have (or add) a column Sequence to your Role table so you could define the sequence in the table itself - and then just to an ORDER BY Role.Sequence.

这篇关于SQL ORDER BY(顺序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆