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 |
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2011-01-05 : 06:53:18
|
| What is best way to handle these type of calculationscol1*col2/(col3/col4)if we use group by clause in query. multiple options like1.((col1*col2)+(colA*colB))/((col3/col4)+(colC/colD))2.(col1*col2)/(col3/col4)+(colA*colB)/(colC/colD)T.I.A |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-01-05 : 07:43:01
|
| As per MSDN "Groups a selected set of rows into a set of summary rows by the values of one or more columns or expressions in SQL Server. One row is returned for each group. Aggregate functions in the SELECT clause <select> list provide information about each group instead of individual rows."So if you needs group wise result then you will need to use the Group By clause. For example Customer_id Amount Deduction1 10.00 1.001 12.00 2.001 13.00 1.00and you want to find the average amount for every cutomer_ID then you will need to do this via group by. Select Customer_ID,Sum(Amount-Deduction) From TableNameGroup by Customer_IDWill return like Customer_Id 1 31.00On the other hand if you need the output like Customer_ID Amount Deduction NetAmount1 10.00 1.00 9.001 12.00 2.00 10.001 13.00 1.00 12.00Then you will need simple operation over columns Select Customer_ID,Amount,Deduction,(Amount-Deduction) NetAmount From TableName |
 |
|
|
|
|
|