0
这段代码很有用,但它很“老派”地寻找。有没有人有更好的方式来选择和分组在一个单一的查询?基本上,这只是一个通用的设置,包括一个头文件表,一个拾音器子表头,一个用于放置的子头表,以及每个表的详细表。t-sql:学术,寻找更高效/更好的查询方式
select h.id
,h.col1 as Customer
,h.col2 as Req
,d.subid as DropId
,d.col1 as DropCity
,d.col2 as DropLoc
,dd.detid as DropDetailId
,dd.col1 as DropSpot
,dd.col2 as DropAWBorPackage
,NULL as PickupId
,NULL as PickUpCity
,NULL as PickUpLoc
,NULL as PickupDetailId
,NULL as PickupLoc
,NULL as PickupAWBorPackage
from [scratch].GenericHeader h
inner join [scratch].GenericSubHeader d on d.id = h.id
inner join [scratch].GenericDetail dd on dd.id = h.id
and dd.id = d.id
and dd.subid = d.subid
UNION ALL
select h.id
,h.col1 as Customer
,h.col2 as Req
,NULL as DropId
,NULL as DropCity
,NULL as DropLoc
,NULL as DropDetailId
,NULL as DropSpot
,NULL as AWBorPackage
,p.sub2id as PickupId
,p.col1 as PickUpCity
,p.col2 as PickUpLoc
,pp.det2id as PickupDetailId
,pp.col1 as PickupLoc
,pp.col2 as PickupAWBorPackage
from [scratch].GenericHeader h
inner join [scratch].GenericSubHeader2 p on p.id = h.id
inner join [scratch].GenericDetail2 pp on pp.id = h.id
and pp.id = p.id
and pp.sub2id = p.sub2id
order by Req,DropId,DropDetailId,PickupId,PickupDetailId
谢谢 - 我是这么认为的,但我只是想确定它不仅仅是一种“习惯的力量”! :) – plditallo