您好,您可以帮我吗?即时通讯收到错误缺少关键字。 参见下面的代码。预先感谢。
SELECT Datum, Wdomain, Lgstkproc, Username,
Case when LGSTKPROC = 'NAVUL'
COUNT (unique username '-'palnumber end nr_pal_per_user_navul,
Case when LGSTKPROC !=‘NAVUL’
COUNT (unique username '-'palnumber end nr_pal_per_user_veplaatst
From (
SELECT USERNAME, RES, RESTYPE, WDOMAIN, LGSTKPROC, LOCNAME, ENDLOCNAME, PALNUMBER, TRUNC(SYSDATE-1) datum
FROM TransportStock$VW TS
WHERE TRUNC(timestamp)<TRUNC(sysdate)-1
AND res NOT LIKE '%CONVS%'
)
Group by Username, Datum, Lgstkproc, Wdomain
答案 0 :(得分:0)
这没有道理:
Case when LGSTKPROC = 'NAVUL'
COUNT (unique username '-'palnumber end nr_pal_per_user_navul,
我推测您想要
count(distinct case when LGSTKPROC = 'NAVUL'
then username || '-' || palnumber
end) as nr_pal_per_user_navul
答案 1 :(得分:0)
您在这里缺少逗号:
SELECT datum,
wdomain,
lgstkproc,
username,
COUNT (DISTINCT CASE WHEN lgstkproc = 'NAVUL' THEN
username || '-' || palnumber
END) AS nr_pal_per_user_navul, --> comma missing here
COUNT (DISTINCT CASE WHEN lgstkproc != 'NAVUL' THEN
username || '-' || palnumber
END) AS nr_pal_per_user_veplaatst
FROM (SELECT username,
res,
restype,
wdomain,
lgstkproc,
locname,
endlocname,
palnumber,
trunc(SYSDATE - 1) datum
FROM transportstock$vw ts
WHERE trunc(timestamp) < trunc(SYSDATE) - 1
AND res NOT LIKE '%CONVS%'
)
GROUP BY username,
datum,
lgstkproc,
wdomain
如果正确格式化编写的代码,事情将更加清楚。
此外,这些COUNT
并没有太大意义-不管CASE
的值如何,两个lgstkproc
都选择相同的值。