Here is the input
This is database to record boreholes drilled at various locations,dates. One client can have more than one type of contract. There is a clause in contract which specifies work rates for different hole depths.These details are in the ContractDetails table. For ex Work rate is 10 units per metre for bore holes upto a depth of 6 metres and 15 units per metre for bore holes above 6 metres depth.
There may be more than one location on a single day for a client. Workdetails table keeps record of the location and related bore hole data for that location.
I hope the table and relationships are correct. Please comment.
Below is summary of related tables :
Clients - ClientID(PK) and other details like name, address etc.
Contracts - ContractID(PK), Client(FK from above), ContractType
ContractDetails - ContractFK(FK from Contracts),QtyLimit, WorkRate
WorkMain - JobID(PK), ContractFK(FK from Contracts)
WorkDetails - LocationID(PK), JobCode(FK)
HoleData - HoleID(PK), LocationCode(FK from above), holeDepth and other fields
Problem -
How to create a query to show sum of borehole depths falling between the QtyLimits mentioned in the ContractDetails for any client on a work day?