求一条SQL语句(100分)

  • 主题发起人 主题发起人 mxiang
  • 开始时间 开始时间
M

mxiang

Unregistered / Unconfirmed
GUEST, unregistred user!
表1 Employee
列 depart_id,job_id,birth_date为日期 查询条件为month(birth_date)=4
表2 depart
列 depart_id,depart_name
表3 job
job_id,job_name

下面的当某条记录的depart_id或job_id 为空时,就查询不出那条记录
怎么写只要是满足month(birth_date)=4,不管depart_id或job_id是否为空都查询出来
数据库为ACCESS

select a.birth_date,b.depart_name,c.job_name from Employee as a,depart as b ,job as c where a.depart_id = b.depart_id and a.job_id =c.job_id and month(a.birth_date) = 4
 
select a.birth_date,b.depart_name,c.job_name
from Employee as a,depart as b ,job as c
where a.depart_id = b.depart_id(+)
and a.job_id =c.job_id(+)
and month(a.birth_date) = 4
以上是Oracle中实现的.
 
晕倒!谁帮帮我呀
 
我在SQLSever中试过了,以上不能使用,不好意思.我再帮你看一下.
 
select *
from item a left join pc b on a.pc=b.pc
where item ='ZPP350R500A'
以上一个SQL可以做为参考!这是在SQLSever中验证过了.
两个字段的,我再帮你试试.
 
不管depart_id或job_id是否为来空
那三个表怎么关联啊,你把depart_id,job_id不为空不就能查到了,具体还是不明白你的意思,你是想实现什么、?
 
这条不知可不可以,
select a.birth_date,b.depart_name,c.job_name
from Employee as a,depart as b ,job as c
where b.depart_id += a.depart_id
and c.job_id+=a.job_id
and month(a.birth_date) = 4
但下面这个就一定可以
select a.birth_date,
(select b.depart_name
from depart as b
where a.depart_id = b.depart_id) as depart_name,
(select c.job_name from job as c where a.job_id = c.job_id) as job_name
from Employee as a
where month(a.birth_date) = 4
 
select a.birth_date,b.depart_name,c.job_name
from (Employee as a left join depart as b on a.depart_id = b.depart_id ) left join job as c on a.job_id =c.job_id
where month(a.birth_date) = 4

这个是在ACCESS数据库中设置的查询SQL,你可以看一下吧!
 
谢谢,就是这样
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
843
import
I
后退
顶部