select substr(to_char(t.grosstime,'yyyy-mm-dd'),9,10) as dates ,
sum(decode(varno, '0102010105000000', netweight,0)) "JMton",
sum(case when t.borrowflag='0'and t.varno='0102010105000000'then 1 else 0 end) as "JMnum",
from table_1 t
where to_char(t.grosstime, 'yyyy-mm') = '2010-10' and t.minecode="150000" and t.transway='1' and t.flag='1' 
group by substr(to_char(t.grosstime,'yyyy-mm-dd'),9,10)
order by substr(to_char(t.grosstime,'yyyy-mm-dd'),9,10)用plsql执行没问题,在报表中就报缺少右括号主要就是第三行case when,该怎么办呢?

解决方案 »

  1.   

    case when似乎没有问题,
    第3行末尾多个逗号
    第2行似乎写得也不够工整。
      

  2.   

    select substr(to_char(t.grosstime, 'yyyy-mm-dd'), 9, 10) as dates,
           sum(decode(varno, '0102010105000000', netweight, 0)) as JMton,
           sum(case
                 when t.borrowflag = '0' and t.varno = '0102010105000000' then
                  1
                 else
                  0
               end) as "JMnum",
      from table_1 t
     where to_char(t.grosstime, 'yyyy-mm') = '2010-10'
       and t.minecode = "150000"
       and t.transway = '1'
       and t.flag = '1'
     group by substr(to_char(t.grosstime, 'yyyy-mm-dd'), 9, 10)
     order by substr(to_char(t.grosstime, 'yyyy-mm-dd'), 9, 10)