在postgres中保持计数数据的最佳方法

时间:2016-02-16 04:45:55

标签: sql postgresql aggregate

我需要为按天划分的某些aggragete日期创建统计信息。 例如:

select 
      (select count(*) from bananas) as bananas_count, 
      (select count(*) from apples) as apples_count, 
      (select count(*) from bananas where color = 'yellow') as  yellow_bananas_count;
显然我会得到:

bananas_count | apples_count     | yellow_bananas_count
--------------+------------------+ ---------------------
           123|              321 |                    15

但是我需要按天分组数据,我们需要知道我们昨天有多少banaras。

我得到的第一个想法是创造一个观点,但在这种情况下,我将无法按日期分割(或者我不知道该怎么做)。

我需要一个以性能为导向的数据库双面实现此任务。

0 个答案:

没有答案