Skip to content

Tag: postgresql

How to select the latest date for each group by number?

I’ve been stuck on this question for a while, and I was wondering if the community would be able to direct me in the right direction? I have some tag IDs that needs to be grouped, with exceptions (column: deleted) that need to be retained in the results. After which, for each grouped tag ID, I need to s…

Use a subquery and a custom value with IN operator

I can’t really find any answer that fits my question. I need to know how I can be able to use a subquery together with a custom value with the IN Operator in SQL. Here is an example of a query I came up with: This query is meant to show posts only from users in a users’ following table

UPDATE based on multiple overlapping conditions

I have a query which essentially transfers a job from one worker to another. The query works fine, but I need to add one additional check: ensure the current job owner (in jobs) is the worker matching @owner and @teamId. This is essentially the condition that I need to add: To the query below: The problem is …

Postgres Counts based on Month and Years

I have a psql table I want to get a break down of users points that shows their points the current month, current year, and the lifetime. I’m a bit lost on how to do this. What would the query look like? The final table should look like this Answer How about conditional aggregation?