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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 query needing sum function/group by?

Author  Topic 

packymyles
Starting Member

21 Posts

Posted - 2008-04-24 : 03:22:46
select bicycle_shop.bicycle_shop_id, bicycle_shop.company_name, order_.unit_price
from order_ inner join bicycle_shop on order_.order_serial_number = bicycle_shop.order_serial_number
order by order_.unit_price DESC;

this query will bring up a few records for each shop, of the one or more bikes they bought and each bike's price, how do i have these come out to a sum(of the price), so that each bike shop will have a sum of revenue. someone told me i need to use group by and the sum function but i dont know how

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-24 : 03:50:32
What did Books Online tell you how to use GROUP BY and SUM?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

packymyles
Starting Member

21 Posts

Posted - 2008-04-24 : 04:04:14
some dude in my class told me i should for what i wanted to do, what would you do to add up the prices by bike shop?? if it seems like i dont know what im asking, sorry
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-24 : 04:11:56
[code]select bicycle_shop.bicycle_shop_id,
bicycle_shop.company_name,
SUM(order_.unit_price)
from order_
inner join bicycle_shop on order_.order_serial_number = bicycle_shop.order_serial_number
group by bicycle_shop.bicycle_shop_id,
bicycle_shop.company_name

order by SUM(order_.unit_price) DESC;[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

packymyles
Starting Member

21 Posts

Posted - 2008-04-24 : 04:42:55
thanks:) where do i put in the "quotation" to name the new column that is made in that query
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-24 : 04:52:39
quote:
Originally posted by packymyles

thanks:) where do i put in the "quotation" to name the new column that is made in that query


select bicycle_shop.bicycle_shop_id,
bicycle_shop.company_name,
SUM(order_.unit_price) AS Quotation
from order_
inner join bicycle_shop on order_.order_serial_number = bicycle_shop.order_serial_number
group by bicycle_shop.bicycle_shop_id,
bicycle_shop.company_name
order by SUM(order_.unit_price) DESC;
Go to Top of Page
   

- Advertisement -