0

我认为需要包括自愿参加活动的成员人数。我收到一个错误“不是单组组功能”。知道如何解决这个问题吗?

CREATE VIEW atbyrd.events__view AS
SELECT e.name, e."DATE", b."LIMIT",b.allocated_amount, COUNT(em.member_id), e.comments
FROM events e INNER JOIN budgets b ON b.event_id = e.id
INNER JOIN event_members em ON em.event_id  = e.id;
4

2 回答 2

1
SELECT e.name, 
       e."DATE", 
       b."LIMIT",
       b.allocated_amount, 
       (select COUNT(member_id) from event_members) as mem_count, 
       e.comments
FROM events e
INNER JOIN budgets b ON b.event_id = e.id
INNER JOIN event_members em ON em.event_id  = e.id;
于 2012-11-26T21:20:30.917 回答
1

您可以使用分析功能count()

SELECT e.name
     , e."DATE"
     , b."LIMIT"
     , b.allocated_amount
     , COUNT(em.member_id) over ( partition by em.event_id )
     , e.comments
  FROM events e 
 INNER JOIN budgets b 
    ON b.event_id = e.id
 INNER JOIN event_members em 
    ON em.event_id  = e.id;

简单地说,这会计算每个成员的数量,event_id但由于它不是聚合函数,因此不需要 GROUP BY。您每收到相同的价值event_id

于 2012-11-26T21:26:31.647 回答