sqlserver三个表联合查询,查询每一张表想要字段一样,不同就用空代替(union all)
create view pjManagementExitView as select wf.id as id,wf.id as requestid,thbg.field002 'field002', (case when wf.pipeid='e4e481638092c23001814ce664c1194e' then '8280810e815fda2601816125dec200a9' else '' end ) as 'field008', thbg.field003 as 'field009','' as 'field010','' as 'field006', '' as 'field007',thbg.field001 as 'field001' from ufu1h0c61564649696627 thbg left join workflowbase wf on wf.id=thbg.requestid where (thbg.isdelete is null or thbg.isdelete=0) and wf.isdelete=0 union all select wf.id as id,wf.id as requestid,thglqb.field002 'field002', (case when wf.pipeid='e4e481638092c23001815abd533119db' then '8280810e815fda2601816125dec200aa' else '' end ) as 'field008', '' as 'field009',thglqb.field003 as 'field010',thglqb.field004 as 'field006', '' as '批复后执行情况',thglqb.field001 as 'field001' from ufb1e3c81655084229175 thglqb left join workflowbase wf on wf.id=thglqb.requestid where (thglqb.isdelete is null or thglqb.isdelete=0) and wf.isdelete=0 union all select wf.id as id,wf.id as requestid,thtcqb.field002 'field002', (case when wf.pipeid='e4e481638092c23001815b3c3dbf1aec' then '8280810e815fda2601816125dec200ab' else '' end ) as 'field008', '' as 'field009',thtcqb.field004 as 'field010',thtcqb.field005 as 'field006', '' as '批复后执行情况',thtcqb.field001 as 'field001' from ufi9d7e91655092685491 thtcqb left join workflowbase wf on wf.id=thtcqb.requestid where (thtcqb.isdelete is null or thtcqb.isdelete=0) and wf.isdelete=0
其中(case when wf.pipeid='e4e481638092c23001814ce664c1194e' then '8280810e815fda2601816125dec200a9' else '' end ) as 'field008'表示,then后面的id是下拉值对应的id