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 |
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-11-17 : 20:14:23
|
| Hi, I have a question about a this query statement. I have 5 different car models. I have been trying to find all the models in 2003 and show the percentage each one had against the total sales for 2003. sales = sale price for carmodletype = car model typesolddate = when car was sold I want to try and display modeltype and percentage soldThank you for any help you can give |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-11-17 : 21:25:28
|
[code]select modeltype, sum(sales) as sales, sum(sales) * 100.0 / (select sum(sales) from sales where solddate between '20030101' and '20031231')from saleswhere solddate between '20030101' and '20031231'group by modeltype[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-11-17 : 22:38:13
|
| So i do not have to create a variable for each model type? With this query, each model type will have different sums. So it will look like this:modeltype Sum Percentage_of_totala 50 .50b 50 .50I thought you had to do variables and other things. |
 |
|
|
intern2424
Yak Posting Veteran
53 Posts |
Posted - 2009-11-17 : 23:26:00
|
| Thanks for the help. i understand it now. |
 |
|
|
|
|
|