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 |
|
acko
Yak Posting Veteran
52 Posts |
Posted - 2004-06-15 : 04:28:52
|
| I want to get the maximum of sum with one select statement.The database is NorhtWind and this is the query.select orderid, sum(quantity)from [order details]where orderid between 11000 and 11005group by orderidorder by 2 descI know that i can use this statement:select Top 1 orderid, sum(quantity)from [order details]where orderid between 11000 and 11005group by orderidorder by 2 descor to use temporery tables but i am interested is there any different way to get only one row with maximum sum per orderid.thanksAlex |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-06-15 : 04:44:54
|
| Whats wrong with your SELECT TOP 1 solution?Kristen |
 |
|
|
LarsG
Constraint Violating Yak Guru
284 Posts |
Posted - 2004-06-15 : 07:08:19
|
| [code]select max(q) from (select sum(quantity) as qfrom [order details]where orderid between 11000 and 11005group by orderid) dt[/code] |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-06-15 : 08:27:07
|
| I assumed, probably wrongly!, that acko wanted the "orderid" tooKristen |
 |
|
|
acko
Yak Posting Veteran
52 Posts |
Posted - 2004-06-15 : 10:01:35
|
| thanks LarsGthat is that i wantedalex |
 |
|
|
|
|
|