Skip to content
Advertisement

Sort Records comparing sums across multiple tables

In SQL Server, I am wanting to bring back all jobs where

To make it easy to see what results I should get I added the following table and updated the inserts into tables.

InvoicedRecieved is ignored for simplicity. Jobs 2,4 Should be returned.

I also need another statement bring back the number of jobs per user that met the above criteria.

Advertisement

Answer

Gordon was correct about the need to sum before comparing, due to the Cartesian product. However as his query isn’t producing the correct result here is the query which does.

DB Fiddle

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement