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 開発者で)

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 に答える