当前位置:首页 » 编程语言 » 多表查询sql语句

多表查询sql语句

发布时间: 2022-01-31 13:35:56

sql语句多表查询

select A.name from A where (select count(C.CS) from C where c.cs not in (select B.CS from B where B.NO=A.NO))=0

⑵ sql语言多表查询

1.查询有不及格成绩的学生姓名
select studName from T_stud
join T_select on T_stud.studNo = T_select.studNo
where score < 60
2.查询有选课的学生姓名和选课数量
select studName,count(*) from T_stud
right join (select studNo,count(*)
from T_select where 1=1 having count(*) > 0
group by studNo ) as A
on T_stud.studNo = A.studNo
3.查询选修了60岁以上老师所教课程的所有学生
select distinct B.studName
from ( select A.studNo,A.studName,teacherNo
from ( select studNo,studName,subNo
from T_stud join T_select
on T_stud.studNo = T_select.studNo ) as A
join T_Sub on T_Sub.subNo = A.subNo ) as B
join T_teacher on T_teacher.teacherNo = B.teacherNo
where T_teacher.teacherAge > 60
4.洪七公老师的学生中,考试不及格的人数(姓名列表)
select distinct B.studName
from ( select A.studNo,A.studName,teacherNo
from ( select studNo,studName,subNo
from T_stud join T_select
on T_stud.studNo = T_select.studNo
where T_select.score < 60 ) as A
join T_Sub on T_Sub.subNo = A.subNo ) as B
join T_teacher on T_teacher.teacherNo = B.teacherNo
where T_teacher.teacherName like '洪七公'
5.洪七公老师教的学生列表以及选修的课程
select B.studName,B.subName
from ( select A.studNo,A.studName,teacherNo,subName
from ( select studNo,studName,subNo
from T_stud join T_select
on T_stud.studNo = T_select.studNo
where T_select.score < 60 ) as A
join T_Sub on T_Sub.subNo = A.subNo ) as B
join T_teacher on T_teacher.teacherNo = B.teacherNo
where T_teacher.teacherName like '洪七公'
6.所有大于50岁老师姓名列表
select teacherName from T_teacher
where teacherAge > 50
7.郭靖的课程平均分
select avg(score) from T_stud
join T_select on T_stud.studNo = T_select.studNo
where studName like '郭靖'
8.王语嫣所选课程名称列表
select subName
from (select subNo
from T_stud join T_select
on T_stud.studNo = T_select.studNo
where studName like '王语嫣') as A
join T_Sub on T_Sub.subNo = A.subNo
9.选修学生最多的课程(这里没有考虑同时多门课程的选修数相等的情况)
select subName
from (select top(1) subNo,count(*)
from T_select
group by subNo order by subNo desc ) as A
join T_Sub on T_Sub.subNo = A.subNo
10.所教学生最多的老师
其他的没时间了,你自己去试着写写吧。。。

⑶ 关于SQL多表联合查询语句

select T2.*
from T2 ,
T1
where T2.工号=T1.工号
and T2.姓名='李刚'
and T2.部门='综合部'

⑷ 写一个多表查询的SQL语句

select * from Mission left join MissionAnswer on Mission.MissionID=MissionAnswer.MissionID where
LessonID=1

⑸ SQL多表查询语句怎么写

SQL多表查询语句的步骤如下:

我们需要准备的材料分别是:电脑、sql查询器。

1、首先,打开sql查询器,连接上相应的数据库表,例如m1表和m2表。

⑹ SQL语句多表查询

1、select *
from sailors where sid in (select sid from reserves where bid='105')

2、select *
from sailors where sid in (select sid from reserves) and age>18

3、select t1.sid,t1.sname
from sailors t1, reserves t2
where t1.sid=t2.sid
group by t1.sid,t1.sname
having count(*)>=2

⑺ SQL 语句多表查询

不知道你是要总个数还是数的总和
如果是总和select a.Username,sum(a.Number) from a jion b on a.UserName=b.UserName group by a.Username
如果是总个数selecta.Username, count(a.Number) from a jion b on a.UserName=b.UserName group by a.Username

⑻ SQL多表查询语句有哪些

不明白你的意思

select * from 表1,表2,....
where

select * from 表1 join 表1 on ..
还有 left join ,right join ,full join,
不知道是不是指这个

⑼ sql语句多个表查询

select 人员.人员id,订单.产品id,订单.订单id,订单.数量 from 人员
left join 订单 on 人员.订单id=订单.id
where 人员.人员id=1

是你想要的结果么?

⑽ sql如何多表查询语句

其实多表查询,用到的关键字,就是像inner join,left join,right join 之类的,根据具本情况,选择自已适合的连接语句。

举个例子吧

select a.studnt_sno,b.sno,c.grade from studnt as a inner join depart as b on a.sno=b.sno left join sc as c on b.cno=c.no

热点内容
qq代挂系统源码 发布:2024-12-28 00:43:48 浏览:376
潜渊症服务器联机怎么存档 发布:2024-12-28 00:42:52 浏览:206
合肥沛顿存储是哪家上市公司持有 发布:2024-12-28 00:42:52 浏览:842
数据库是系统软件吗 发布:2024-12-28 00:32:50 浏览:286
剪映压缩帧率 发布:2024-12-28 00:19:52 浏览:1
解压生石灰 发布:2024-12-28 00:19:51 浏览:580
运算算法英语 发布:2024-12-28 00:15:41 浏览:610
python输出引号 发布:2024-12-28 00:15:35 浏览:218
java0基础教程 发布:2024-12-27 23:48:31 浏览:784
电脑文件夹选项不见了 发布:2024-12-27 23:39:15 浏览:836