注册 登录
编程论坛 SQL Server论坛

求两个SQL语句

陈天 发布于 2007-09-29 19:01, 712 次点击
有Student表(ID:自增长,Name:姓名,Age:年龄),现求以下两个SQL语句:
a):求年龄在20-30岁之间,张姓学生按年龄升序排序;
b):求有相同年龄学生的全部信息;

请哪位仁兄学姐赐教!!!不胜感激!!!
9 回复
#2
purana2007-09-29 21:00

create table #student(
id int identity(1,1) not null primary key,
name nvarchar(60),
age smallint
)

insert into #student(name,age) values(N'张天',16)
insert into #student(name,age) values(N'李四',24)
insert into #student(name,age) values(N'赵六',31)
insert into #student(name,age) values(N'张七',40)
insert into #student(name,age) values(N'王五',10)
insert into #student(name,age) values(N'陈八',22)
insert into #student(name,age) values(N'马九',16)
insert into #student(name,age) values(N'曾十',24)

--1
select * from #student where age between 20 and 30 order by name asc

--2
select * from #student where age in(select age from #student group by age having count(age)>1) order by id

drop table #student

#3
shuzai19852007-09-29 21:18
1.select * from #student where age between 20 and 30 and name like '张%' order by name
#4
chenxiang2007-09-29 23:49

女孩权益保护协会
请问那个#student 是什么啊,我试了你的命令,可是select * from #student,drop table #student的时候却找不到表,到企业管理器中也没有发现,是怎么回事,麻烦指导下

#5
chenxiang2007-09-29 23:57
我把#去掉则一切正常
#6
gggg0072007-09-30 08:44

创的临时表

#7
bygg2007-09-30 09:56

create table #student(
id int identity(1,1) not null primary key,
name nvarchar(60),
age smallint
)

这里创建的临时表

#8
陈天2007-10-06 21:22
不错,看了受教了,谢谢!
#9
purana2007-10-06 21:33

努力学习..

#10
缘吇弹2007-10-07 00:50

接LS:
天天上网..

1