標籤:join 查詢 com select 9.png 結果 第一個 -- info
第一個sql語句
select companyname gsmc,zb zhibiaofrom t_gsndzb left join t_companycodeon t_gsndzb.gsbh=t_companycode.companyid
查詢結果:
第二個sql語句
SELECT min(companyname) gsmc,cast(round(sum(t_xstj.hsje)/10000,2) as numeric(20,2)) ndje FROM t_xstj left join t_companycode on t_companycode.companyid = t_xstj.gsbhwhere datediff(year,sj,getdate())=0 group by gsbh
查詢結果:
合并成一張表的語句:
select isnull(a.gsmc,b.gsmc) gsmc,isnull(a.zhibiao,0) zhibiao,isnull(b.ndje,0) ndjefrom ( --第二個表查詢結果-- select companyname gsmc,zb zhibiao from t_gsndzb left join t_companycode on t_gsndzb.gsbh=t_companycode.companyid ) A FULL JOIN ( --第二個表查詢結果-- SELECT min(companyname) gsmc, cast(round(sum(t_xstj.hsje)/10000,2) as numeric(20,2)) ndje FROM t_xstj left join t_companycode on t_companycode.companyid = t_xstj.gsbh where datediff(year,sj,getdate())=0 group by gsbh) b on a.gsmc=b.gsmc
結果:
sqlserver 把兩個sql查詢語句查詢出來的兩張表合并成一張表