Skip to content

Create A shift summary, with a shift spanning over 2 days

I have a data set like the sample below. I need to query and summarize the number of transactions per shift. The problem is that the shift cycle does not align with the normal hours of a day. Eg. The shift for day 2020-01-01 will start at 06:00 AM on 2020-01-01 and end at 06:00 AM on 2020-01-02 Below are

SQL selecting most recent row inside join

I have 2 tables companies and invoices I want to select all companies with their most recent invoice price. I don’t seem to get it working. This is what I tried: But the query loads very long and I don’t know why. The structure looks like this: companies invoices The BC_ID is the same as the compa…

SELECT with a variable

I have 3 tables : t_object : With all the classes t_operation : With all the operations, link with t_object.Object_ID = t_operation.Object_ID t_operationtag : With all the tag value for each operation, link with t_operation.OperationID = t_operationtag.ElementID I try to get an list for each of my operation (…

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 …