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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select Questioin

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2010-06-04 : 02:01:29
Hi All,

I want to select data, but i want it join data with same price.
normal select give

productname,productoption,quantity,price
t-shirt 1,size:s,1,23,00
t-shirt 2,size:m,1,20,00
t-shirt 3,size:m,1,20,00

What i want is:
productname,productoption,quantity,price
t-shirt 1,size:s,1,23,00
t-shirt 2,size:m,2,20,00

So that it adds the Quantity even if productname,productoption is different. only the Price must be the same

Thanks a lot,

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-04 : 03:40:51
productname,productoption,sum(quantity) as quantity,price from table
group by productname,productoption,price


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mike13
Posting Yak Master

219 Posts

Posted - 2010-06-04 : 05:03:46
quote:
Originally posted by madhivanan

productname,productoption,sum(quantity) as quantity,price from table
group by productname,productoption,price


Madhivanan

Failing to plan is Planning to fail



Thanks a lot, that did the trick ;-)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-04 : 05:14:35
Maybe you can do a correction in your first post?
't-shirt 3' should be 't-shirt 2' otherwise the output would be
productname,productoption,quantity,price
t-shirt 1,size:s,1,23,00
t-shirt 2,size:m,1,20,00
t-shirt 3,size:m,1,20,00
and not
productname,productoption,quantity,price
t-shirt 1,size:s,1,23,00
t-shirt 2,size:m,2,20,00



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-04 : 05:59:10
quote:
Originally posted by webfred

Maybe you can do a correction in your first post?
't-shirt 3' should be 't-shirt 2' otherwise the output would be
productname,productoption,quantity,price
t-shirt 1,size:s,1,23,00
t-shirt 2,size:m,1,20,00
t-shirt 3,size:m,1,20,00
and not
productname,productoption,quantity,price
t-shirt 1,size:s,1,23,00
t-shirt 2,size:m,2,20,00



No, you're never too old to Yak'n'Roll if you're too young to die.


I guessed so

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -