use LOL
go
create table zuoye
(
code int primary key identity(1,1),
name varchar(20),
class char(3),
sex char(2),
teacher varchar(20),
birth datetime ,
height varchar(50)
)
go
insert into zuoye values('韩寒','1','男','孙坚','1901-01-02','180')
insert into zuoye values('王石','2','男','孙策','1901-02-03','168')
insert into zuoye values('韩庚','3','男','孙权','1901-03-04','175')
insert into zuoye values('刘翔','1','男','孙坚','1900-04-15','186')
insert into zuoye values('王晶','2','男','孙策','1902-04-05','166')
insert into zuoye values('刘璇','3','女','孙权','1889-10-02','170')
insert into zuoye values('王菲','1','女','孙坚','1888-08-08','169')
insert into zuoye values('姚明','2','男','孙策','1769-01-31','250')
insert into zuoye values('边雅琪','3','女','孙权','1922-10-15','170')
insert into zuoye values('肖责','1','男','孙坚','1903-01-19','178')
insert into zuoye values('马莉雅','2','女','孙策','1902-03-25','172')
insert into zuoye values('薄瓜','3','男','孙权','1902-03-24','171')
insert into zuoye values('慈禧','1','女','孙坚','1827-09-10','186')
insert into zuoye values('翠花','2','女','孙策','1903-03-09','179')
insert into zuoye values('王龙','3','男','孙权','1902-02-10','199')
insert into zuoye values('夏种','1','男','孙坚','1903-03-03','198')
insert into zuoye values('诸葛亮','2','男','孙策','1922-04-05','120')
insert into zuoye values('小乔','3','女','孙权','1933-03-04','185')
insert into zuoye values('大桥','1','女','孙坚','1988-02-03','175')
insert into zuoye values('孙尚香','2','女','孙策','1923-03-05','172')
go
select *from zuoye
--查询男同学身高在170以上
select *from zuoye where sex='男' and height>170
--查询有多少姓王的同学
select *from zuoye where name like'王%'
--查询有几个班级
select distinct class from zuoye
--查询女的身高在168,170,172这三个数
select *from zuoye where sex='女' and height in('168','170','172')
--查询第5-8条数据,按身高排序后的
select top 3 *from zuoye where code not in (select top 5 code from zuoye order by height desc ,code desc)order by height desc
--查询所有男同学身高高于所有女同学身高
select *from zuoye where sex='男' and height>all
(
select height from zuoye where sex='女'
)
drop table zuoye
--删除表