精典SQL语句

1.两表全成一表
select * from (select dwbm,xqid,dwmc,dwbz,xtbz,pxxh from xt_xqdwb  union (select xqid,1,xqmc,'0',null,null from xt_xq)) a where a.dwbm>'0' and a.xqid='1' and a.dwbz='0'  order by a.pxxh

select id,   (select dwmc  from xt_xqdwb   where dwbm = finance_jsyfbx.bmbm    and xqid = '1'  and dwbz = '0') as bmbmmc,
           bmbm,
       zs,
       yfze,
       to_char(bxrq, 'yyyy-mm-dd') as bxrq
  from finance_jsyfbx
 where (tjid, id) in
       (select tjid, min(id) from finance_jsyfbx group by tjid) and bmbm='1'
 order by id desc
select * from ((select to_char(dwbm),xqid,dwmc,dwbz,xtbz,pxxh from xt_xqdwb where dwbm>0) union (select 'XQ'||xqid,1,xqmc,'0',null,null from xt_xq where xqid>0)) a where a.xqid='1' and a.dwbz='0' order by a.pxxh

2.字段合并
select gwid,gwmc, gwmc||(case when (select dwmc from xt_xqdwb where dwbm = ssxt)='----全部----' then '' else '--------'||(select dwmc from xt_xqdwb where dwbm = ssxt) end)  as dwmc  from xt_gwbmb order by gwid
原文地址:https://www.cnblogs.com/draeag/p/895945.html