Skip to content

Tag: postgresql

Postgres: Count multiple events for distinct dates

People of Stack Overflow! Thanks for taking the time to read this question. What I am trying to accomplish is to pivot some data all from just one table. The original table has multiple datetime entries of specific events (e.g. when the customer was added add_time and when the customer was lost lost_time). Th…

What is wrong with my stored procedure SQL query on PostgreSQL?

I tried many times with or without the semicolon but still shows me the error message. ERROR: syntax error at or near “INSERT” LINE 13: INSERT INTO Advertisement(ad_id, business_id, requested_on… ^ SQL state: 42601 Character: 712 I am sure the table constraint and sequence are all correct bu…

SQL subqueries PostgreSQL 12

I’m having a table similar to this: first last date pos john doe 18-03-2021 harris potter 10-06-2021 john doe 10-05-2021 harris potter 14-06-2021 jessica potter 14-06-2021 kermit foster The use case is as follow: The pos column correspond to a positive covid test The date column correspond to the vaccin…

Generate dates in-between date and date after

Based on the table below I want to generate the dates in between, by dividing the revenue by the number of days from the date in the current row and the row below. Example: Revenue in US on 1 January 2020 is 120. The next revenue date for the US is 5 January 2020. There are 4 days in betweeen.

disaggregate 3d time periods into daily

table_1 shows the aggregation of the revenue by different geographies I would like to disaggregate the 3d period to daily: table_2 as a next step, I would like to also change the table_2 format into table_3: From table_1 to table_2, I am not sure. From table_2 to table_3, I am thinking of: With the code above…