数据库自联表查询

来源:互联网 发布:windows文件监控 编辑:程序博客网 时间:2024/05/19 18:10

select  HTTYPE, t1.Factory, t1.H_user as 财务1,t2.H_user as 财务2,t3.H_user as 财务3 , t4.H_user as 财务4
 from notices as t1,notices as t2,notices as t3 , notices as t4 ,heton where
 t1.H_Type='0' and t1.type='1'   and t1.Factory='XM' and t1.Factory=heton.Site  and t2.H_Type='1' and t2.type='1' and t2.Factory='XM' and t2.Factory=heton.Site
 and t3.H_Type='2' and t3.type='1' and t3.Factory='XM' and t3.Factory=heton.Site  and t4.H_Type='3' and t4.type='1' and t4.Factory='XM' and t4.Factory=heton.Site

 

 

正式的代码

select distinct t11.notects,t1.H_factory as TSite,t1.H_user as 财务1 ,t2.H_user as 财务2,t3.H_user as 财务3,t1.SNumber
from C_User as t1 ,C_Contract_Item as t11,C_User as t2,C_User as t3,C_Contract_Item as t22,C_Contract_Item as t33
where t1.H_type='0' and t1.Type='1' and t1.H_factory='XM' and t1.H_Factory=t11.Site and t1.SNumber=t11.numbers
and t2.H_type='1' and t2.Type='1' and t2.H_factory='XM' and t2.H_Factory=t22.Site and t2.SNumber=t22.numbers
and t3.H_type='2' and t3.Type='1' and t3.H_factory='XM' and t3.H_Factory=t33.Site and t3.SNumber=t33.numbers
and t1.SNumber=t2.SNumber  and t2.SNumber=t3.SNumber

原创粉丝点击