小编The*_*ice的帖子

Joining a function and a view

我有一个功能 get_sa001 and a view Axis_RefCustomer.

当我get_sa001在一段时间内单独执行我的函数时,比如说 2016 - 2017,执行时间约为 6 秒。

SELECT d."Selling_date",  d."Value_in_EUR", d."Value_in_currency", d."Site"
FROM report.get_sa001('2016-01-01'::date, '2017-03-31'::date, 32) AS d
Run Code Online (Sandbox Code Playgroud)

当我在视图上执行选择时Axis_RefCustomer,它运行大约 1 秒。

Select a."Selling_currency" FROM report."Axis_RefCustomer" AS a
Run Code Online (Sandbox Code Playgroud)

当我将它们连接在一起时,执行时间约为 39 秒!

SELECT d."Selling_date",
a."Selling_currency", 
d."Value_in_EUR", 
d."Value_in_currency", 
d."Site"
FROM report.get_sa001('2016-01-01'::date, '2017-03-31'::date, 32) AS d 
LEFT JOIN report."Axis_RefCustomer" 
AS a ON d."Site" = a."Site" 
AND d."Internal_reference" = a."Reference_internal" 
AND d."Customer_code" = a."Customer_code"
Run Code Online (Sandbox Code Playgroud)

Is there anyway to reduce the amount of time my query …

postgresql performance execution-plan plpgsql

5
推荐指数
1
解决办法
169
查看次数

每周每列计数 PostgreSQL

假设我有一个包含 10 列和 2 周 (w1 w2) 的 PostgreSQL 表,其中包含 5 个国家/地区。看起来像这样的东西:

数据

我想做的是每周和每列的计数,如下所示:

结果

postgresql count group-by

1
推荐指数
1
解决办法
1178
查看次数