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 |
egemen_ates
Yak Posting Veteran
76 Posts |
Posted - 2013-09-27 : 03:49:42
|
How can i write this query ?TABLECODE AMOUNT100 20100.01 10100.01.10 7OUTPUTCODE AMOUNT100 37100.01 17100.01.10 7Thanks for answers |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-09-27 : 08:27:18
|
[code]select code, sum(amount) over(order by len(code) desc) as Amountfrom yourTable;[/code] |
|
|
egemen_ates
Yak Posting Veteran
76 Posts |
Posted - 2013-09-27 : 11:33:07
|
quote: Originally posted by James K
select code, sum(amount) over(order by len(code) desc) as Amountfrom yourTable;
Thanks for answer but im not using your query this table.how can i write this query another way ?TABLECODE AMOUNT100 20100.01 10100.01.10 7200 10200.01 6OUTPUTCODE AMOUNT100 37100.01 17100.01.10 7200 16200.01 6 |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-09-27 : 11:43:09
|
[code]select code, sum(amount) over(partition by LEFT(code,3) order by len(code) desc) as Amountfrom yourTable;[/code] |
|
|
|
|
|