Skip to content

Tag: postgresql

Complicated PostgreSQL query to group by multiple columns

I have PostgreSQL table with client_id, date, smp_number, vs_type, vs_amount: What I want to achieve is to group by client_id and month and then to get the total debit sum and the total credit sum by month in distinct columns and the last smp_number in each month. The result should be: Hope this makes sense, …

Import dump file containing a database dump to dbeaver

I have a database dump in thisdb_2022.dump binary file that I’m trying to import to dbeaver, but I haven’t found a way to import the database so I can see it. I found the below in the dbeaver forum but when I try to follow the instructions and create a new connection I don’t see any option I…

UNION ALL Slower than N queries

This question is following this question where I wanted to select the MAX value of multiples fields while retrieving each row. The accepted answer with UNION ALL worked like a charm but I now have some scaling issues. To give some context, I have more than 3 million rows in my matches table and the filters us…

Calculate the difference of dates in one column

DB-Fiddle Expected result: I want to calculate the date_difference between the MAX and the MIN order_date per campaign. So far I was able to come up with this query: This solution would work if the dates would be in two separate columns. How do I have to modify the query to also make it work if they are in on…

SQL Joins not working correctly when no data present

I’ve got the following code, where I build a tag from an entity Each tag has an id, name, description and how many questions it has, how many it has in a day, and how many it has in a week. The problem is, I can’t seem to display tags that have no questions tied to them, and also if

How do combine two Queries or is it only one?

Question: How do combine two Queries or is it only one? Example: I have two exact similar tables my PostgreSQL Database. info_table and info_table_dump with the exact same columns date_at, name, color and length . Now i want to know if there are entries in info_table_dump that do not exist in info_table. Ther…