Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
cwfontan
Yak Posting Veteran
87 Posts |
Posted - 2009-09-02 : 14:15:45
|
I have 3 fields I want to count and group based on same moves from pick to load and load to deltoso if the load to delto is the same as the pick to load group it together and count. see belowtablepick | load | deltomove1 move2 move3move2 move3 move2move1 move2 move1move1 move3 move2move2 move3 move2resultsqty | from | to2 move1 move23 move2 move33 move3 move21 move2 move11 move1 move3 thanks |
|
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2009-09-02 : 14:26:27
|
| [code]CREATE TABLE #temp (pick VARCHAR(10),[LOAD] VARCHAR(10),delto VARCHAR(10))insert into #tempselect 'move1', 'move2', 'move3'union all select 'move2', 'move3', 'move2'union all select 'move1', 'move2', 'move1'union all select 'move1', 'move3', 'move2'union all select 'move2', 'move3', 'move2'SELECT sum(qty) AS qty , A.[from], A.[to]FROM ( SELECT COUNT(*) AS qty, [LOAD] AS [From], delto AS [to] FROM #temp GROUP BY [load],delto union SELECT COUNT(*) AS qty, pick AS [from], [load] AS [to] FROM #temp GROUP BY pick, [load] ) AS AGROUP BY A.[From],A.[to] [/code]An infinite universe is the ultimate cartesian product. |
 |
|
|
cwfontan
Yak Posting Veteran
87 Posts |
Posted - 2009-09-02 : 14:43:56
|
| great thanks!! |
 |
|
|
|
|
|
|
|