I have a table that stores the information about user calls in a call center. The table has a call_id, date when the call was made, actual date and time of the call, call type and a score associated with the call.
My requirement is to calculate a 40 day moving average of the score with respect to the call day. The 40 day should start from the previous day from the call date. If there are no call in …
我需要根据给定月份的每一行计算给定 client_id 的过去 12 个月的销售额总和。
这是按客户按月汇总的销售额的初始表(此处针对特定客户进行过滤511656A75):
CREATE TEMP TABLE foo AS
SELECT idclient, month_transac, sales
FROM ( VALUES
( '511656A75', '2010-06-01', 68.57 ),
( '511656A75', '2010-07-01', 88.63 ),
( '511656A75', '2010-08-01', 94.91 ),
( '511656A75', '2010-09-01', 70.66 ),
( '511656A75', '2010-10-01', 28.84 ),
( '511656A75', '2015-10-01', 85.00 ),
( '511656A75', '2015-12-01', 114.42 ),
( '511656A75', '2016-01-01', 137.08 ),
( '511656A75', '2016-03-01', 172.92 ),
( '511656A75', '2016-04-01', 125.00 ),
( '511656A75', '2016-05-01', 127.08 ),
( '511656A75', '2016-06-01', 104.17 ), …Run Code Online (Sandbox Code Playgroud) postgresql performance join optimization postgresql-9.6 query-performance
首先看看StackOverflow上的这个问题。
我希望完成相同的任务,但我还需要ST_Union向我的查询添加聚合函数(PostGIS )。
如何将答案DISTINCT与聚合结合使用...
我试过了:
SELECT DISTINCT ON (name, zonedistrict_id)
ST_Union(geom) as geom, gid, name, zonedistrict_id, zonestyle_id, longname
FROM zones
ORDER BY name, zonedistrict_id, zonestyle_id;
Run Code Online (Sandbox Code Playgroud)
哪个尖叫:
column "zones.gid" must appear in the GROUP BY clause or be used in an aggregate function
这很奇怪,因为如果我删除ST_Union(geom) as geom,,则查询有效。但它没有联合几何。