如何在postgresql中按周截断数据?

时间:2016-07-07 15:15:35

标签: sql postgresql

SELECT 1 - Cast (a.count AS FLOAT) / Cast (b.count AS FLOAT) AS percentage 

FROM 

(SELECT Count(DISTINCT request_id) FROM quotes) AS a, 

(SELECT Count(*) 
FROM requests 
WHERE  user_id IS NOT NULL AND state NOT IN ( 'rejected', 'unconfirmed' )) AS b 

请求和引号表都有created_at时间列。

我应该把这一行放在哪里

date_trunc('week', quotes.created_at + '1 day'::interval) AS "week_num"

获取百分比截断的百分比表?

0 个答案:

没有答案