有5个结构相同的表,表1、表2、表3、表4、表5,对这5个表单条件查询Select * from 表1 where 入职日期='2014-04-20' union all Select * from 表2 where 入职日期='2014-04-20' union all..........union all Select * from 表5 where 入职日期='2014-04-20' 查询是成功的,如果再加上一个查询条件 ,岗位=普工,表达式该怎么写?
解决了
Select * from 表1 where 入职日期='2014-04-20' and 岗位='普工' union all Select * from 表2 where 入职日期='2014-04-20' and 岗位='普工' union all..........union all Select * from 表5 where 入职日期='2014-04-20 and 岗位='普工'
SQL 多表多条件查询语句
答案:2 悬赏:60 手机版
解决时间 2021-03-05 00:53
- 提问者网友:动次大次蹦擦擦
- 2021-03-04 00:33
最佳答案
- 五星知识达人网友:鱼忧
- 2021-03-04 00:55
select * from
(select * from 表1
union all
select * from 表2
union all
select * from 表3
union all
select * from 表4
union all
select * from 表5)tb
where 入职日期='2014-04-20' and 岗位='普工'
(select * from 表1
union all
select * from 表2
union all
select * from 表3
union all
select * from 表4
union all
select * from 表5)tb
where 入职日期='2014-04-20' and 岗位='普工'
全部回答
- 1楼网友:春色三分
- 2021-03-04 02:30
你这语句写的自己都哭了吧,一般sql拼接是这么做的,我给你写个伪代码
设初始sql= "select * from 档案 where 1=1"
设combo1,2,3,4分别为4个查询条件
if combo1.text<>全部
then sql=sql&"and 姓名=‘"&姓名变量&“’”
......
if combo4.text<>全部
then sql=sql&"and 体重=‘"&体重变量&“’”,1=1在百万数量级以上会有效率问题,但小型应用可不考虑。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯