我想编写一个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
可能是我的格式错误。有人可以帮我写这样的查询吗?
答案 0 :(得分: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;