(1)有3个表t1,t2,t3,他们均有一个int类型的列id,t1的记录为(1),t2的记录为(1,1,2),t3的记录为(1,1,1,2,2)
分别写出下面2个sql 语句的执行结果
select t1.id,t2.id,t3.id from t1 left join t2 on t1.id = t2.id left join t3 on t3.id = t2.id
select t1.id,t2.id,t3.id from t1 left join t2 on t1.id = t2.id right join t3 on t3.id = t2.id
(2)有2个表t1,t2。他们各有2个列a,b表中记录内容如下:
t1表: ab t2表: ab
12 11
32 32
请写出查询不在t2表中出现,仅在t1表中存在的记录,注意判断的依据是整条记录,即已a,b字段为依据,例如,对
示例数据应该返回t1表中a=1,b=2这条记录。(3)已知关系模式
S(sno,sname) 学生关系 sno为学号,sname为姓名
S1(cno,cname,cteacher) 课程关系 cno为课程号,cname为课程名,cteacher为任课教师
SC(sno,cno,scgrade)选课关系 scgrade为成绩
分别写出下面2个sql 语句的执行结果
select t1.id,t2.id,t3.id from t1 left join t2 on t1.id = t2.id left join t3 on t3.id = t2.id
select t1.id,t2.id,t3.id from t1 left join t2 on t1.id = t2.id right join t3 on t3.id = t2.id
(2)有2个表t1,t2。他们各有2个列a,b表中记录内容如下:
t1表: ab t2表: ab
12 11
32 32
请写出查询不在t2表中出现,仅在t1表中存在的记录,注意判断的依据是整条记录,即已a,b字段为依据,例如,对
示例数据应该返回t1表中a=1,b=2这条记录。(3)已知关系模式
S(sno,sname) 学生关系 sno为学号,sname为姓名
S1(cno,cname,cteacher) 课程关系 cno为课程号,cname为课程名,cteacher为任课教师
SC(sno,cno,scgrade)选课关系 scgrade为成绩
解决方案 »
- 谁有LECCO SQL Expert For SQL Serve?r需要支持SQL SERVER2005
- SQL Server的连接问题(在线等啊)
- 触发器更新 INSERTED?
- 如何实现修改数据库里以前建过表的时间?
- 有关查询语句的写法
- MSSQL2000 视图数据转换为视图
- 各位帮帮忙!错误;不允许从数据类型 varchar 到数据类型 money 的隐性转换。
- 请教sql语句,涉及本期金额和上期金额的
- 我的SQL数据库为什么没有换行和空格啊?
- 使用事务实现互斥的问题
- |zyciis|如何在经过复杂的查询后,过虑掉指定字段重复的记录,谢谢 有代码
- 怎样提取SQL 2005中 表的一个列的指定的字符串
select * from t1 where not exists(select * from t2 where t2.a=t1.b and t2.b=t1.b)
from t1 left join t2 on t1.id = t2.id left join t3 on t3.id = t2.id
/*
id id id
----------- ----------- -----------
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1(所影响的行数为 6 行)*/
select t1.id,t2.id,t3.id
from t1 left join t2 on t1.id = t2.id right join t3 on t3.id = t2.id
/*
id id id
----------- ----------- -----------
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
NULL NULL 2
NULL NULL 2(所影响的行数为 8 行)*/2\
select * from t1 where not exists(select 1 from t2 where t1.a=t2.a and t1.b=t2.b)3\
select b.cteacher,b.cname,count(c.sno) 不及格学生人数
from s1 b,sc c where b.cno=c.cno and c.scgrade<60
group by b.cteacher,b.cname
(1) select t1.id,t2.id,t3.id from t1 left join t2 on t1.id = t2.id left join t3 on t3.id = t2.id
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
select t1.id,t2.id,t3.id from t1 left join t2 on t1.id = t2.id right join t3 on t3.id = t2.id
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
NULL NULL 2
NULL NULL 2(2)
;with tb
as
(select t2.a as c,t2.b as d,t1.*
from t1 left join t2 on t1.a=t2.a and t1.b=t2.b
)
select a,b from tb where c is null(3)select cteacher,cname,count(sc.sno)
from s1 ,sc,s
where s1.cno=sc.cno and s.sno=sc.sno and sc.scgrade<60
group by cteacher,cname
selcet cout(*) from SC where scgrade<'60'显示不及格人数