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
 Grouping items in a view

Author  Topic 

AMB
Starting Member

6 Posts

Posted - 2006-11-29 : 08:44:56
Hi,
I have a view of all quotes on our system which contains the quote number and the value of each item in the quote. I am trying to group the quotes so each entry only appears once. (NOt worried about the value field as there is a subtotal field that can be used in its place). An example would be......

QuoteNo Subtotal
quote001 54.52
quote002 10.35
quote002 10.35
quote003 25.01
quote004 31.23
quote004 31.23
quote004 31.23

I am trying to get it like this.....

QuoteNo Subtotal
quote001 54.52
quote002 10.35
quote003 25.10
quote004 31.23

Can anyone help?

Thanks,
AMB

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-29 : 08:47:50
[code]Select QuoteNumber, max(subtotal) as SubTotal
from Table
group by QuoteNumber[/code]

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

Sean_B
Posting Yak Master

111 Posts

Posted - 2006-11-29 : 08:48:57
Have you tried doing select distinct QuoteNo, Subtotal from quotes ?


Sean_B
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-29 : 08:50:00
or more simple:

Select Distinct QuoteNumber, SubTotal
from Table


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-29 : 09:32:10
Learn SQL

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

Madhivanan

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

- Advertisement -