资源描述:
《SQlServer2005数据库及应用教师使用资源 教学课件 ppt 作者 徐人凤 公司sql招聘试题.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一公司sql招聘试题、1.数据库表结构: 字段名称
2、 类型
3、 长度 Id
4、 Int
5、 4 Name
6、 Varchar
7、 20 Rank
8、 Int
9、 4 表中的数据: Id
10、 Name
11、 Rank 1
12、 I
13、 1 1
14、 have
15、 2 1
16、 a
17、 3 1
18、 dream
19、 4 2
20、
21、 Oh
22、 1 2
23、 my
24、 2 2
25、 god!
26、 3 查询结果: ID
27、 Name 1
28、 I have a dream 2
29、 Oh my god! 请写出查询语句。 2.假设有2个表:A表和B表,表结构相同,都如下: 字段名
30、 类型 BeginDate
31、 date EndDate
32、 date Name
33、
34、 varchar StrNum
35、 int Number
36、 int 请写出查询语句,得出所有在A表记录且不存在于B表中的记录。(A表与B表中相同字段的记录都必须不同) create table T(id int,name varchar(20),rank int) insert T select 1, 'I', 1 union all select 1, 'have', 2 union all select 1, 'a', 3 union all select 1, 'dream', 4 union all select 2, 'Oh', 1
37、 union all select 2, 'my', 2 union all select 2, 'god!', 3 create function fun(@id int) returns varchar(4000) as begin declare @re varchar(4000) set @re='' select @re=@re+name+' ' from T where id=@id order by rank return @re end select id, name=dbo.fun(id) from T group by
38、id --result id name ----------- --------------------- 1 I have a dream 2 Oh my god! (2 row(s) affected)--创建用户定义函数 create function f_str(@id int) returns varchar(8000) as begin declare @ret varchar(8000) set @ret = ''
39、 select @ret = @ret+','+name from table1 where id = @id set @ret = stuff(@ret,1,1,'') return @ret end go --执行 select id,name=dbo.f_str(id) from table1 group by id order by 1 go select * from tableA A where not exists ( select 1 from tableB where a.name=A.name and ...
40、.....)create table A(BeginDate datetime, EndDate datetime, Name varchar(100), StrNum int, Number int) create table B(BeginDate datetime, EndDate datetime, Name varchar(100), StrNum int, Number int) select * from A where not exists (select *