我想将这些涉嫌重复(实际上不是)的条目合并到属性ID(PTY_ID)组下的唯一条目中,这就是结果:
以下是我的查询代码:
➜ new_ghost npm install --production
npm WARN cannot run in wd ghost@0.11.2 node core/server/utils/npm/preinstall.js (wd=/var/www/new_ghost)
[1] 14831 killed npm install --production
更确切地说,我想显示一个显示许多功能的唯一属性条目。我怎么能这样做?
顺便说一句,我正在使用oracle 11g。所以我尝试了LISTAGG,但效果不好......
我只是试图像这样使用LISTAGG:
SELECT distinct P.PTY_ID, (P.PTY_UNITNUM||' '||P.PTY_STREET||', '
||P.PTY_SUBURB||', '||P.PTY_CITY||' '||P.PTY_POSTCODE) address,
T.P_type_name, F.FEAT_name
FROM property P, PROPERTY_TYPE T, feature F, property_FEATURE K
WHERE P.P_TYPE_ID = T.P_TYPE_ID
AND K.feat_id = F.feat_id
AND K.pty_id = P.pty_id
ORDER BY p.pty_id;
我收到此错误说:" FROM关键字找不到预期位置"。错误发生在" select distinct P.PTY_ID, (P.PTY_UNITNUM||' '||P.PTY_STREET||', '
||P.PTY_SUBURB||', '||P.PTY_CITY||' '||P.PTY_POSTCODE) address,
T.P_type_name, LISTAGG(F.FEAT_name, ',') WITHIN GROUP (ORDER BY
P.PTY_ID) AS FEATURES
from property P, PROPERTY_TYPE T, feature F, property_FEATURE K
where P.P_TYPE_ID = T.P_TYPE_ID
and K.feat_id = F.feat_id
and K.pty_id = P.pty_id
group by P.PTY_ID, P.PTY_UNITNUM, P.PTY_STREET, P.PTY_SUBURB, P.PTY_CITY,
P.PTY_POSTCODE, T.P_type_name
order by p.pty_id;
"
答案 0 :(得分:0)
尝试在'功能'之前删除'AS'...
LISTAGG(F.FEAT_name, ',') WITHIN GROUP (ORDER BY P.PTY_ID) AS FEATURES
LISTAGG(F.FEAT_name, ',') WITHIN GROUP (ORDER BY P.PTY_ID) FEATURES
SELECT DISTINCT P.PTY_ID,
(P.PTY_UNITNUM
||' '
||P.PTY_STREET
||', '
||P.PTY_SUBURB
||', '
||P.PTY_CITY
||' '
||P.PTY_POSTCODE) address,
T.P_type_name,
LISTAGG(F.FEAT_name, ',') WITHIN GROUP (ORDER BY P.PTY_ID) FEATURES
FROM property P,
PROPERTY_TYPE T,
feature F,
property_FEATURE K
WHERE P.P_TYPE_ID = T.P_TYPE_ID
AND K.feat_id = F.feat_id
AND K.pty_id = P.pty_id
GROUP BY P.PTY_ID,
P.PTY_UNITNUM,
P.PTY_STREET,
P.PTY_SUBURB,
P.PTY_CITY,
P.PTY_POSTCODE,
T.P_type_name
ORDER BY p.pty_id;