Aggregate Functions and Group By Problems
Posted
by David Stein
on Stack Overflow
See other posts from Stack Overflow
or by David Stein
Published on 2010-01-04T19:12:25Z
Indexed on
2010/05/17
2:30 UTC
Read the original article
Hit count: 288
tsql
|sql-server-2000
If we start with the following simple SQL statement which works.
SELECT sor.FPARTNO, sum(sor.FUNETPRICE)
FROM sorels sor
GROUP BY sor.FPARTNO
FPartNo is the part number and the Funetprice is obviously the net price. The user also wants the description and this causes a problem. If I follow up with this:
SELECT sor.FPARTNO, sor.fdesc, sum(sor.FUNETPRICE)
FROM sorels sor
GROUP BY sor.FPARTNO, sor.fdesc
If there are multiple variations of the description for that part number, typically very small variations in the text, then I don't actually aggregate on the part number. Make sense?
I'm sure this must be simple. How can I return the first fdesc that corresponds to the part number? Any of the description variations would suffice as they are almost entirely identical.
Edit: The description is a text field.
© Stack Overflow or respective owner