December 8, 2010 at 4:56 am
I have a table with Int Column, sample table with data like bellow
ItemID, Name, Quantity
------------------
1 A 2
2 B 1
3 C 3
4 D 4
5 E 5
so I need to write a query to return all possible combinations with matching Quantity column.
E.G. if I passed 8
need result set like bellow (2+1+5 = 8, 3+5 = 8, 1,3,4 = 8)
combinationID, Quantity, NoOfItems
1 2 3
1 1 3
1 5 3
2 3 2
2 5 2
3 1 3
3 3 3
3 4 3
advice me
Harshana Weerasinghe
www.harshana.net
www.DevSmart.net
December 8, 2010 at 6:39 am
What have you tried so far and where do you get stuck?
December 8, 2010 at 6:55 am
You're going to need to recursively cross-join the table with itself, essentially.
This question is almost always school work. Is it this time, too?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply