每个组的成员都有不同的过滤器
A different filter for each group by member
对于每个主题,我想在特定日期后过滤他们的记录。但是,我想用作过滤器的日期对于每个主题都是不同的。有没有办法按主题分组,然后为每个组使用不同的 having 从句?
你可以这样做:
select tbl.subject
,count(*) as record_count
-- add other aggregate functions as required
from thetable tbl
join (values
('somesubject' ,'2005-04-03')
,('othersubject','2008-07-06')
,('yetanother' ,'2013-12-11')
-- add as many subjects as required
) cutoff(subject,min_dt) on cutoff.subject = tbl.subject and cutoff.min_dt::date <= tbl.date_column
group by tbl.subject
对于每个主题,我想在特定日期后过滤他们的记录。但是,我想用作过滤器的日期对于每个主题都是不同的。有没有办法按主题分组,然后为每个组使用不同的 having 从句?
你可以这样做:
select tbl.subject
,count(*) as record_count
-- add other aggregate functions as required
from thetable tbl
join (values
('somesubject' ,'2005-04-03')
,('othersubject','2008-07-06')
,('yetanother' ,'2013-12-11')
-- add as many subjects as required
) cutoff(subject,min_dt) on cutoff.subject = tbl.subject and cutoff.min_dt::date <= tbl.date_column
group by tbl.subject