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.
| Author |
Topic |
|
hallyvaux
Starting Member
12 Posts |
Posted - 2011-05-02 : 17:14:11
|
| Can you help me understand group by?If you are using the select statement and selecting aggregate functions with and alias, then you use the group by clause and group by a field that you used in more then one aggregate function, what is it grouping by? EX.SELECT NAME "Proudct Name", SUM(ORDERQTY)"Qty Ordered" ,SUM(SELLPRICE) "Price Sold" ,SUM(SELLPRICE) * SUM(ORDERQTY) "Total Sale"FROM GS_SALES,GS_PRODUCTSWHERE GS_SALES.PRODID = GS_PRODUCTS.PRODIDGROUP BY SELLPRICE, NAME,ORDERDATE,ORDERQTYORDER BY SELLPRICE DESC, NAME DESC;SELLPRICE is part of "price sold" AND "Total Sales" so when I use group by, what is going on? Also if you see where this is just a ridiculous way to get this info, please tell me because I am partially lost. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|