Skip to content

Tag: postgresql

WHERE a AND b returns just WHERE b

I have 2 tables which I want to join and return only those records which: Have the same value with other records in one of the columns. Have certain values in other column. These are my requests: List only those records which have the same value with other records in grnz column: List only those records which…

SQL subquery to find overlapping customers

I’m working on writing a SQL query that would allow me to find customers who bought a certain variety of a product during specific sale dates and then subsequently bought a different product within a different date range. I want to use a subquery in the from clause to search for the second group of cust…

Postgres SQL attribution over time range

I’m using Postgres 11 and trying to figure out if I can do this in a single query. Suppose I have two tables: When I join these tables by uuid, Event2 rows should be attributed to a particular Event1.id up to when a newer Event1.id is active. For example, if I have these rows: Event1: Event2: I would ge…

How to get data from Json to multiple column PostgreSQL

I want to extract many objects (not all object) in JSON but don’t want to type for every single thing like this: Here my DEMO show real data and case, how to extract to multiple columns and cast it to exact data type (float, integer) I refer this question, can I use json_to_record for this or other meth…