日期:2014-05-17  浏览次数:21013 次

oracle sql 组合查询问题
SQL code


select 
(
declare
  pm_name varchar(20);

begin
  select name into pm_name from tblsex where type=u.type
  dbms_output.put_line(pm_name);

  if pm_name = '男' then
    select name into pm_name from tblsex where type=u.type
  else
    --输出'女'
  end if;

end;
) xb
,
u.*
from users u

这条SQL有错,如何改为正确?




------解决方案--------------------
SQL code

SELECT DECODE(T.JQLY, NULL, NVL(G.GZDMC, '拟制'), '加签') GZDMC, T.*
  FROM GWXXB T
  LEFT JOIN (SELECT ROW_NUMBER() OVER(PARTITION BY GWID ORDER BY GZDMC) ROW_,
                    GWID,
                    GZDMC
               FROM GWGZD) G
    ON T.GWID = G.T.GWID
   AND G.ROW_ = 1
 WHERE ROWNUM <= 5
 ORDER BY ROWNUM ASC;