有两个表A,B
A表(班级表):
部门号,班级号,班级名
B表(学生表):
部门号,班级号,学号
部门号为:1,2,3,4,.....
班级号为:1,2,3,4,.....
不同部门号可以有相同的班级号
要求:根据A表中的班级名(含有"98"字样或含有"99"字样),查询B表中的学号
我的方法:
select 学号 from 学生表 where 部门号 in(select 部门号 from 班级表 where 班级名 like "__99_" )
and 班级号 in (select 班级号 from 班级表 where 班级名 like "__98_" )
可惜不对!
忘达人指点!谢谢!
多表多条件查询问题
答案:4 悬赏:20
解决时间 2021-04-21 05:47
- 提问者网友:痞子房西
- 2021-04-21 00:56
最佳答案
- 二级知识专家网友:而你却相形见绌
- 2021-04-21 01:43
select 学号 from 学生表 where 部门号 in(select 部门号 from 班级表 where 班级名 like '__9[89]_' )
或用你的方法,不过 逻辑运算符 AND 要改成 OR
select 学号 from 学生表 where 部门号 in(select 部门号 from 班级表 where 班级名 like '__99_' )
or 班级号 in (select 班级号 from 班级表 where 班级名 like '__98_' )
或用你的方法,不过 逻辑运算符 AND 要改成 OR
select 学号 from 学生表 where 部门号 in(select 部门号 from 班级表 where 班级名 like '__99_' )
or 班级号 in (select 班级号 from 班级表 where 班级名 like '__98_' )
全部回答
- 1楼网友:温柔刺客
- 2021-04-21 05:17
select 学号 from 学生表 b inner join 班级表 a on b.部门号=a.部门号 and b.班级号=a.班级号 where (b.班级名 like '%98%') or (b.班级名 like '%99%')
- 2楼网友:一起来看看吧
- 2021-04-21 04:38
我不知道你的两个表之间有什么关联,如果只有部门号关联,那将 AND A.班级号=B.班级号 去掉.
select 学号 from 学生表 A, 班级表 B
WHERe A.部门号=B.部门号 AND A.班级号=B.班级号
AND B.部门号 LIKE '%99%'
AND B.班级名 LIKE '%98%'
GROUP BY 学号
- 3楼网友:如果这是命
- 2021-04-21 03:11
select max(aname),max(adatetime),max(btitle),max(bdatetime ) from(
select a.name aname,a.datetime adatetime,'' btitle, '' bdatetime from a where a.place=1
union all
select '','',b.title,b.datetime from b where b.place=1) t
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯