Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL按多列从序列顺序中选择所有记录_Sql_Sql Server_Sql Order By - Fatal编程技术网

SQL按多列从序列顺序中选择所有记录

SQL按多列从序列顺序中选择所有记录,sql,sql-server,sql-order-by,Sql,Sql Server,Sql Order By,下表 id firstname lastname 1 john smith 2 john doe 3 john fox 4 adam white 5 brad grant 6 michael jordan 7 amy young 如何选择约翰·福克斯之前的所有人按姓、名排序? 我想出了下面的方法,但看起来真的很笨拙 select * from student wher

下表

id  firstname   lastname
1   john        smith
2   john        doe
3   john        fox
4   adam        white
5   brad        grant
6   michael     jordan
7   amy         young
如何选择约翰·福克斯之前的所有人按姓、名排序? 我想出了下面的方法,但看起来真的很笨拙

select * from student where firstname<'John'
union
select * from student where firstname='John' and lastname<='fox'

select*from student where firstname您似乎希望根据firstname/lastname的字母顺序进行排序。这似乎很奇怪,但有一种方法是:

select s.*
from student s
where firstname < 'john' or
      firstname = 'john' and lastname <= 'fox'
order by firstname, lastname;
选择s*
来自学生
其中名为“约翰”或

firstname='john'和lastname使用您正在使用的数据库标记您的问题。我的sql server是MS sql 2012。它似乎不支持我刚才尝试的选项2。谢谢你的帮助!杨。SQL Server不支持元组比较。这很不幸。我真的很喜欢这里的清洁。
select s.*
from student s
where (firstname, lastname) <= ('john', 'fox')
order by firstname, lastname;