2

我想编写一个 sql,我想在其中计算具有不同状态代码的单个表中的记录。我写了一个这样的查询

select 
(    
    (
        select count(*) as "Entry"
        from cn_grc_hdr hdr
        where hdr.unit_code = '03' and 
            hdr.crt_dt > '12-may-2013' and 
            hdr.status = 'E'
    ),
    (
        select count(*) as "Authorised" 
        from cn_grc_hdr hdr
        where hdr.unit_code = '03' and 
            hdr.crt_dt > '12-may-2013' and 
            hdr.status = 'A'   
    )
)
from dual

当我执行此查询时,它显示错误(在 oracle sql developer 中)

ORA-00907:缺少右括号 00907. 00000 - “缺少右括号” 原因:操作:错误在行:5 列:5

可能是我的格式错误。有人可以帮我写这样的查询吗?

4

1 回答 1

2

我已经重写了查询

select DECODE(status, 'E', 'Entry', 'A', 'Authorised') as Status , count(*) 
FROM table
where unit_code = '03' 
and crd_dt > to_date('12-May-2013', 'dd-MON-yyyy') 
and status in ('A', 'E')
GROUP BY status; 
于 2013-09-30T14:38:09.313 回答