select to_char(date::DATE, ‘YYYY’) as year,sum(shares) as shares, sum(visits) as visits
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01′ group by year order by year
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01′ group by year order by year
select to_char(date::DATE, ‘YYYY-MM’) as month,sum(shares) as shares, sum(visits) as visits
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01′ group by month order by month
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01′ group by month order by month
select to_char(date::DATE-(extract(dow from date::TIMESTAMP)-1||’day’)::interval, ‘YYYY-mm-dd’) week,
sum(shares) as shares, sum(visits) as visits
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01′ group by week order by week
sum(shares) as shares, sum(visits) as visits
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01′ group by week order by week
select to_char(date::DATE, ‘YYYY-MM-DD’) as day,sum(shares) as shares, sum(visits) as visits
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01′ group by day order by day
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01′ group by day order by day
select to_char(date::DATE, ‘YYYY-MM-DD HH24′) as hour,sum(shares) as shares, sum(visits) as visits
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01’ group by hour order by hour
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01’ group by hour order by hour
select to_char(date::DATE, ‘YYYY-MM-DD HH24:MI ‘) as minute,sum(shares) as shares, sum(visits) as visits
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01’ group by minute order by minute
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01’ group by minute order by minute
select to_char(date::DATE, ‘YYYY-MM-DD HH24:MI:SS ‘) as second,sum(shares) as shares, sum(visits) as visits
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01’ group by second order by second
from database_table
where date >=’2019-01-01′ and date <=’2020-01-01’ group by second order by second
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:Postgresql 动态统计某一列的某一值出现的次数实例postgreSql分组统计数据的实现代码postgresql数据库使用说明_实现时间范围查询postgresql 实现查询某时间区间的所有日期案例postgresql 计算时间差的秒数、天数实例
© 版权声明
文章版权归作者所有,未经允许请勿转载。