你有几个错误。正如@cricket_007 指出的那样,您在两个计数表达式之间缺少逗号。但是您的filter
子句也有无效的语法-至少在Oracle中不存在;您在字符串文字周围使用了双引号而不是单引号;日期字符串周围的引号更奇怪;并且您依赖于日期格式的 NLS 设置。
如果我了解您的尝试,这更接近您的需要:
SELECT
count(case when pc.collection = 'players' then pf.pref_selection end)
OVER (partition BY pc.user_id) AS Avg_players,
count(case when pc.collection = 'teams' then pf.pref_selection end)
OVER (partition BY pc.user_id) AS Avg_teams
FROM NBA_OWNER.PREFERENCES pf
inner join NBA_OWNER.PREF_COLLECTIONS pc on pc.ID=pf.COLLECTION_ID
where pc.LAST_UPDATE_DATE > date '2016-09-30'
虽然输出可能不是很有用。对于每个用户 ID,您可能会获得多行,每行都显示总计数(您avg
出于某种原因调用过)。您可能只想查看每个 ID 的计数一次,并查看它们与哪个 ID 相关,所以我认为您需要聚合而不是分析计数:
SELECT
pc.user_id,
count(case when pc.collection = 'players' then pf.pref_selection end)
AS Avg_players,
count(case when pc.collection = 'teams' then pf.pref_selection end)
AS Avg_teams
FROM NBA_OWNER.PREFERENCES pf
inner join NBA_OWNER.PREF_COLLECTIONS pc on pc.ID=pf.COLLECTION_ID
where pc.LAST_UPDATE_DATE > date '2016-09-30'
group by pc.user_id