2021
01-17
01-17
PostgreSQL完成按月累加的操作
背景统计某个指标,指标按照月进行累加,注意需要按省份和年份进行分组。方法一、使用自关联--with按月统计得到中间结果WITHymsAS(SELECTregionid,SUM(getnum)ASgetnum,SUM(dealnum)ASdealnum,to_char(qndate,'yyyy-MM')ASyearmonthFROMt_queuenumberGROUPBYregionid,to_char(qndate,'yyyy-MM')ORDERBYregionid,yearmonth)--查用子查询解决。SELECTs1.regionid,s1.yearmonth,getnum,dealnum,(SELECTSUM(getnu...
继续阅读 >