1. 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
2. sql语句多个表查询
select 人员.人员id,订单.产品id,订单.订单id,订单.数量 from 人员
left join 订单 on 人员.订单id=订单.id
where 人员.人员id=1
是你想要的结果么?
3. SQL语句实现多表查询
select a.keb001,a.keb003,a.keb004,a.keb007,a.keb016,b.kea003,c.raa001,d.qka005,d.aka006
FROM JSKKEB a, JSKKEA b,SGMRAA c,SGMQKA d
WHERE a.keb001=b.kea001 and a.keb016=c.raa011 and c.raa001=d.qka004
and b.kea003 = 你的日期条件(这里很奇怪,我加上去的条件无法更新上去,抱歉。一定要注意日期格式)
这是oracle数据库的sql语法,请根据你自己数据库的语法稍加修改。
如果a,b,c,d别名不行,可以把别名去掉,前缀直接用表名。
4. 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
5. 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
6. 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.所教学生最多的老师
其他的没时间了,你自己去试着写写吧。。。
7. SQL多表查询语句有哪些
不明白你的意思
select * from 表1,表2,....
where
select * from 表1 join 表1 on ..
还有 left join ,right join ,full join,
不知道是不是指这个
8. 关于SQL多表联合查询语句
select T2.*
from T2 ,
T1
where T2.工号=T1.工号
and T2.姓名='李刚'
and T2.部门='综合部'
9. mysql多表查询sql语句怎么写
一使用SELECT子句进行多表查询
SELECT 字段名 FROM 表1,表2 … WHERE 表1.字段 = 表2.字段 AND 其它查询条件
SELECT a.id,a.name,a.address,a.date,b.math,b.english,b.chinese FROM tb_demo065_tel AS b,tb_demo065 AS a WHERE a.id=b.id
注:在上面的的代码中,以两张表的id字段信息相同作为条件建立两表关联,但在实际开发中不应该这样使用,最好用主外键约束来实现
二使用表的别名进行多表查询
如:SELECT a.id,a.name,a.address,b.math,b.english,b.chinese FROM tb_demo065 a,tb_demo065_tel b WHERE a.id=b.id AND b.id='$_POST[textid]'
SQL语言中,可以通过两种方式为表指定别名