Hi All,I hope that this is in the correct place! I have a single table with the following columns of interest.[code]DateOfBusiness FKStoreId CheckNumber FKItemId QSQuickComboID2016-04-01 00:00:00.000 6366 30001 905207 3064[/code]What it is basically showing, is every single item that is sold and which check it is associated to. What i want to find, is a count for the number of items in a check, when there is a specific item on a check. It is worth noting that there may be multiple instances of the same cheque number, so the primary key for this table would be a combination of DoB, FKStoreID & CheckNumberI can find all check numbers that contain the relevant item with (note i have added the date in just to reduce the number of results returned):[code] select CheckNumber from dpvHstGndItem where FKItemId = 200112 and DateOfBusiness = '2016-04-01'[/code]And i am attempting to use the results of this to count the number of items on the check numbers that are returned using:[code]select FKStoreId, DateOfBusiness, CheckNumber, COUNT(fkitemid)from dpvHstGndItemwhere CheckNumber IN ( select CheckNumber from dpvHstGndItem where FKItemId = 200112 and DateOfBusiness = '2016-04-01')and DateOfBusiness = '2016-04-01'group by fkstoreid, DateOfBusiness, CheckNumberorder by fkstoreid, DateOfBusiness[/code]This does return a count of the items on the checks, however it returns a count of the items on all checks, not just ones that contain the FKItemID 200112.This is my first attempt at this level of complexity of sql for about 10 years since i studied it at University!
↧