【发布时间】:2017-04-28 20:42:30
【问题描述】:
尝试在 oracle 12c 中解决问题 (SQL: query to show how many users have each property (grouped))。
with data (id, name, a, b, c, d) as
(
select 1, 'name1', 'yes', 'yes', '', 'yes' from dual union all
select 2, 'name2', 'yes', '', '', 'yes' from dual union all
select 3, 'name3', '', 'yes', '', 'yes' from dual union all
select 4, 'name4', 'yes', 'yes', '', 'yes' from dual union all
select 5, 'name5', '', '', 'yes', 'yes' from dual
)
,
coll (a,b,c,d) as
(
select count(a) a, count(b) b, count(c) c, count(d) d from data
)
select * from coll
unpivot
(
val for (col) in (a, b, c, d)
);
工作正常并产生所需的结果。
而
with data (id, name, a, b, c, d) as
(
select 1, 'name1', 'yes', 'yes', '', 'yes' from dual union all
select 2, 'name2', 'yes', '', '', 'yes' from dual union all
select 3, 'name3', '', 'yes', '', 'yes' from dual union all
select 4, 'name4', 'yes', 'yes', '', 'yes' from dual union all
select 5, 'name5', '', '', 'yes', 'yes' from dual
)
--,
--coll (a,b,c,d) as
--(
select count(a) a, count(b) b, count(c) c, count(d) d from data -- Line 1685
--)
--select * from coll
unpivot
(
val for (col) in (a, b, c, d)
);
产生以下错误。
ORA-00904:“D”:无效标识符 00904. 00000 - “%s:无效标识符” *原因:
*行动: 行错误:1,685 列:50
有人可以帮忙找出原因吗?
【问题讨论】:
-
输出应该是什么样子的?还有多少列 a,b,c,d 你有?修好了吗?
-
两个发布的例子都产生同样的错误online fiddle: