Skip to content

Tag: postgresql

JOIN on Subquery Based on Date Evaluation

I have a query that includes a subquery that references one of the tables that my query joins on, but I also need to do an evaluation on the field returned from the subquery in my WHERE clause. Here’s the current query (rough example) – My subquery is currently returning the latest date from the c…

Postgres LEFT JOIN not returning nulls?

Not sure why this is happening, but I have this query: And the item table has 100 elements. I’m looking for the resulting rows to be grouped by user_id and have each array be 100 items long. That is, if the value is not present in the vote table, to just instead sub in a 0 in its place. Unfortunately

PostgreSQL count of each status per day

I have the following table: I also have a table with every calendar day from 2019-11-01 to 2019-12-31. I need to find out how many occurrences of each status exist per calendar day for the time span listed above. If a status is Opened on 2019-12-14 and Pending on 2019-12-17, I need to count that it was Opened…

SQL multiple SELECTs very slow to run

I have the following query (Postgres) which gives the correct results, but it is very slow. Any ideas how I can make it faster? SELECT DISTINCT(vesselimo), vesselname, (SELECT COUNT(portid) FROM …