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 2000 Forums
 SQL Server Development (2000)
 SQL Group By Help

Author  Topic 

jrockfl
Posting Yak Master

223 Posts

Posted - 2004-11-23 : 12:27:10
I'm trying to group SalesAmount and Slspsn_No, but its not working.

If I do GROUP BY OEORDLIN_SQL.Qty_Ordered * OEORDLIN_SQL.Unit_Price) * ((100 - OEORDLIN_SQL.Discount_Pct) / 100), slspsn_no

It groups it a little better, but not totally.

SELECT (OEORDLIN_SQL.Qty_Ordered * OEORDLIN_SQL.Unit_Price) * ((100 - OEORDLIN_SQL.Discount_Pct) / 100) AS SalesAmount,
OEORDHDR_SQL.Slspsn_No
FROM OEORDLIN_SQL INNER JOIN
OEORDHDR_SQL ON OEORDLIN_SQL.Ord_No = OEORDHDR_SQL.Ord_No
WHERE (OEORDLIN_SQL.Prod_Cat IN ('A68', 'A69', 'A83', 'A84')) AND (OEORDHDR_SQL.Ord_Dt >= '20041101') AND (OEORDHDR_SQL.Ord_Dt <= '20041130')

nr
SQLTeam MVY

12543 Posts

Posted - 2004-11-23 : 12:40:07
What are you trying to do?
With that group by you could use distinct instead.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-11-23 : 13:05:53
how about some sample data and what you are trying to return.

- Jeff
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 2004-11-23 : 13:30:56
I'm trying to display the sales person number and their total sales
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-11-23 : 13:33:58
you need to use the SUM() aggregate function. Again, sample data and expected results will help us help you more.

- Jeff
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 2004-11-23 : 13:34:00
oh nevermind, i see what im doing wrong. i just needed a SUM()
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 2004-11-23 : 13:34:33
Thanks Dr. Cross Join, you are right, I just figured it out.
Go to Top of Page
   

- Advertisement -