rszl数据表和crjsj数据表的关联查询
'查找姓名为 '某某某' 或者 卡号为99999999 或者 编号为 '号号号' 的crjsj资料 和人事资料
;----------------------------------------------------------------------
SELECT crjsj.id, rszl.bh, crjsj.kh, rszl.xm, crjsj.time8, crjsj.date8, crjsj.mjjbh, crjsj.mjkzqbh, crjsj.syqk, crjsj.crjqk
FROM crjsj RIGHT JOIN rszl ON crjsj.kh = rszl.kh
WHERE
crjsj.kh=99999999
or
crjsj.kh=(select kh from rszl where xm='某某某' and dele=0)
or
crjsj.kh=(select kh from rszl where bh='号号号' and dele=0)
and date8 between #2005-1-26# and #2005-7-26#
;----------------------------------------------------------------------
select a.id,b.bh,a.kh,b.xm,a.date8,a.time8 from crjsj a,rszl b where
a.kh=b.kh and
(a.kh=1 or
a.kh=(select top 1 kh from rszl where xm='某某某' and dele=0) or
a.kh=(select top 1 kh from rszl where bh='号号号' and dele=0)
) and
a.date8 between #2005-7-26# and #2005-7-26#
;----------------------------------------------------------------------