如题:选择所有classnumber =1或rating =9的记录,使得classnumber =1且rating =9的记录排在最前面,并且classnumber =1且rating =9的记录按id降序排列。
下面是我模仿的例子:
create table myCreateTBPractice
(
Iname nvarchar(50) not null,
classnumber int not null,
studentid int primary key ,
rating int Null
)
注意:创建表的时候用的是()而不是{} 其次字段之间用‘,’而不用‘;’ 可空的用null;
我们采用关键字Union
select * from [myCreateTBPractice] where classnumber = '1' and rating = '9' (1) union all
select * from [myCreateTBPractice] where classnumber = '1' and rating != '9' union all
select * from [myCreateTBPractice] where rating = '9' and classnumber != '1' order by studentID desc
注意:黑体字部分不能放在位置(1),要放在末尾。