- Invoice (InvoiceNo, CustID, OutletID, Date) PK(InvoiceNO)
- InvoiceItems (InvoiceNo, ItemID, Quantity, Discount) PK(InvoiceNO,ItemID)
PLz tell me solution of Above mention Query using nested Method Using these Two tables structure. I am unable to solve it.
Advertisement
Answer
This should do the trick.
x
Select i1.CustID, i2.CustID
From
(Select InvoiceNo,count(*) as nb
From InvoiceItems
Group by InvoiceNo) as a,
(Select InvoiceNo,count(*) as nb
From InvoiceItems
Group by InvoiceNo) as b,
Invoice as i1,
Invoice as i2
Where a.InvoiceNo = i1.InvoiceNo
and b.InvoiceNo = i2.InvoiceNo
and a.InvoiceNo < b.InvoiceNo
and a.nb = b.nb;