Problem with MIN+SUM | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Problem with MIN+SUM


I have a table with data as follows: | ProcessName | EquipmentID | TimeProcessed | …
———————————————–
| Process 1 | 1 | 123 |
| Process 2 | 2 | 456 |
| Process 2 | 3 | 789 |
| Process 3 | 4 | 123 |
… The problem is in some cases same process can be done with many equipment. In those cases I have a rule to select an equipment with smallest ID, but I should have a sum of both of TimeProcessed -values for that process. It’s easy to use GROUP BY, find smallest equipment ID and use that, but how to take a sum of the two? -Mika
Sorry, but from your sample data it is not clear, at least to me, what the final result should look like. Can you post this? —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)

Can you post the result you want from those sample data? Madhivanan Failing to plan is Planning to fail

Thanks for your prompt reply. What it should result is:
Process1 | 1 | 123
Process2 | 2 | 1245
Process3 | 4 | 123 So for Process2 it sums the two TimeProcessed values together and takes smallest EquipmentID.
Try this select ProcessName ,min(EquipmentID),sum(TimeProcessed) from yourTable group by ProcessName
Madhivanan Failing to plan is Planning to fail
]]>