Topic: SQL request
Help with one request, brain does not turn on...
There are 2 tables from which it is necessary to generate request by a following principle:
In the first table there are 2 fields:
Inventory. ID_Branch - int
Inventory. InvDate - Datetime
It is a lot of subdividings and at various times on them inventory was led...
And table Storage:
id_branch - int
Data - datetime
Qnty - numeric (12,2)
As to me to transfer in the second subquery lastInvent thus
That all transactions got to a subquery since the maximum date from the first table...
select inv. *, s.* FROM
select a.id_branch, max (a. InvDate) as lastInvent from Inventory a Group by a.id_branch
Left join (select id_branch, sum (qnty) as totQnty from storage where data> = LastDate ) s
ON inv.id_branch = s.id_branch
All thanks in advance...