A
A
Artem2017-03-30 12:08:35
PostgreSQL
Artem, 2017-03-30 12:08:35

How to get the difference between the values ​​of a column when querying for a time period?

I collect information about applications. According to the report - for the day. I can get the number of installs for the lifetime of the app, while the rest of the data is broken down by day.
The task - I want to calculate the difference between the day of the request - and the previous day, having the total number of installations, inside the request for all data on the application for the period.

SELECT "vr"."installs" as "installs" -(SELECT "vr"."installs" FROM "vungle_raport" "vr" WHERE "vr"."date" BETWEEN DATE '2017-02-28' - '-1 day' AND BETWEEN DATE '2017-02-30' - '-1 day')
FROM "app" "vr"
WHERE "vr"."date" BETWEEN '2017-02-28' AND '2017-03-30'

Obviously, this is not possible, since the subquery will return not an integer, but an array that cannot be subtracted.
Maybe somehow you can take two requests, and subtract the values ​​of one from the other?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2017-03-30
@freeExec

Make a LEFT JOIN and filter out the results by NULL where no matches were found.

A
Alexander Korotkov, 2017-03-30
@smagen

I didn't quite understand what exactly needs to be done. But, I think, you need to look towards WINDOW FUNCTIONS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question