b.SetCount AS SetB, c.SetCount AS SetC FROM #Example a INNER JOIN #Example b ON a.OrderID<> b.OrderID INNER JOIN #Example c ON a.OrderID<> c.OrderID AND c.OrderID<> b.OrderID GROUP BY a.SetCount,b.SetCount,c.SetCount HAVING(SUM(a.SetCount + b.SetCount + c.SetCount)= 12 )Thanks for the ideas. I''m not sure yet what it was, but soon after Iread your post I came up with a solution. I think I''ve completelysolved my root problem, and I kind of feeel silly for not seeing it inthe first place... I guess I never found any examples.Anyway, this seems to be the fastest and easiest way to (in my case) toidentify a group of "orders" where the total number of "sets" = 12.More on this later, here''s what I got so far...--Again, instead of inviting families to fill exactly 12 seats,--I''m looking for the fewest OrderIDs--where the number of Sets they contain totals exactly 12.--This returns a value of 2,3,7CREATE TABLE #Example(OrderID int,SetCount int NULL)INSERT #Example VALUES (1,8)INSERT #Example VALUES (2,7)INSERT #Example VALUES (3,6)INSERT #Example VALUES (4,3)INSERT #Example VALUES (5,2)INSERT #Example VALUES (6,DEFAULT)SELECT TOP 1 a.SetCount AS SetA,b.SetCount AS SetB,c.SetCount AS SetCFROM #Example aINNER JOIN #Example b ON a.OrderID <> b.OrderIDINNER JOIN #Example c ON a.OrderID <> c.OrderIDAND c.OrderID <> b.OrderIDGROUP BY a.SetCount, b.SetCount, c.SetCountHAVING (SUM(a.SetCount + b.SetCount + c.SetCount) = 12) 这篇关于帮我摆脱诅咒......拜托。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-14 16:25