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

SQL语句列转行.
本帖最后由 s63403048 于 2013-05-20 10:54:24 编辑
RT.列转行成功.
但是带入机构条件就提示不是单组分组函数.
去掉

    b.branchcode||'-'||b.branchname as bran,

这一段,就可以显示了
(需求里必须显示机构咧.)
麻烦了



 --按脱保原因调查表的统计方法
 select 
    b.branchcode||'-'||b.branchname as bran,
   sum(case s.offreasons when '保单价格原因'  then count(distinct  c.licenseno || substr(engineno, length(engineno) - 5, 6))   else null end)  as offresions1 ,
    sum(case s.offreasons when  '其它主体手续费较高'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions2,
    sum(case s.offreasons when  '其它主体赠送礼品'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions3,
    sum(case s.offreasons when   '理赔服务问题'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions4,
    sum(case s.offreasons when   '过户、转卖他人'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions5,
    sum(case s.offreasons when   '车辆报废'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions6,
    sum(case s.offreasons when   '业务员离职或转其它支公司'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions7,
    sum(case s.offreasons when   '本身为市场业务,流动性交强'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions8,
    sum(case s.offreasons when   '其它主体关系客户'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions9,
    sum(case s.offreasons when   '已在人保兄弟公司承保'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions10,
    sum(case s.offreasons when   '已在其它主体承保'  then   count(distinct c.licenseno || substr(engineno, length(engineno) - 5, 6))  else null end) as  offresions11,
    sum(case s.offreasons when   '其它原因'  then   count(distinct c.licenseno || substr