Thread: Aggregate function in SQL Server
- 01-15-2009 08:07 AM #1
Aggregate function in SQL Server Hi,
Please find the below query in sql server.I need to get the sum of the field.The below qry is working fine.
Code :select (arr.PROD),
arr.Calendar_Month_N,arr.fld_inv,
(arr.Fld_Inv/sum(arr.Fld_Inv)) as cum_fld,
((arr.Fld_Inv/sum(arr.Fld_Inv))*(arr.ARR_3MRA))as fldinv_calc,
arr.ARR_3MRA
from DRV_Data_200811 arr
JOIN Test_Smry_200811 NTF
ON (ARR.Prod=NTF.Prod And ARR.Calendar_Month=NTF.Calendar_Month)
group by ARR.PRODUCT,arr.Calendar_Month_N,arr.ARR_3MRA,arr.fld_inv
************************************
But I need to get one more summation which is
(sum((arr.Fld_Inv/sum(arr.Fld_Inv))*(arr.ARR_3MRA))) as glob in the select field.
but I am getting error as
Could any one please help me on the sameCode :"Msg 130, Level 15, State 1, Line 1
Cannot perform an aggregate function on an expression
containing an aggregate or a subquery."
- Club-Oracle Complementary E-Books and Magazines
Get your free Complementary Copy of Oracle Magazine
You can also browse the Free Magazines and E-Books section to see the complete list of free magazines, e-books and Whitepapers.
- 01-15-2009 12:01 PM #2
Re: Aggregate function Hi Sowmya,
Neither this is SQL SERVER forum , Nor I am Sql Server expert.
Anyway we can reproduce this error in Oracle also.
See the following examples.
Code :SQL> SELECT DEPTNO , COMM ,COMM/SUM(SAL) X
2 FROM EMP2
3 GROUP BY DEPTNO , COMM;
DEPTNO COMM X
---------- ---------- ----------
20 450 .5625
30 500 .181818182
30 700 .318181818
10 300 .047619048
20 400 .056537102
30 300 .06741573
10 500 .204081633
20 100 .033333333
8 rows selected.
SQL> SELECT DEPTNO ,COMM , SUM(COMM/SUM(SAL)) X
2 FROM EMP2
3 GROUP BY DEPTNO , COMM;
SELECT DEPTNO ,COMM , SUM(COMM/SUM(SAL)) X
*
ERROR at line 1:
ORA-00937: not a single-group group function
Now we can sum the x again using an outer sub query as below .
Code :SQL> SELECT DEPTNO, SUM(X) X
2 FROM
3 (SELECT DEPTNO , COMM ,COMM/SUM(SAL)X
4 FROM EMP2
5 GROUP BY DEPTNO , COMM )
6 GROUP BY DEPTNO ;
DEPTNO X
---------- ----------
30 .56741573
20 .652370436
10 .25170068
SQL>
You can do the same in SQL Server .i guess.
I dont know whether Cub-oracle support non-oracle related posts.
Anyway , your are lucky to get the reply .
Raj.
- 01-15-2009 01:15 PM #3
Re: Aggregate function in SQL Server Moved this to the "Other Databases" Section!
Learn Oracle with Oracle forum. Check out The Technology Blog
- 01-15-2009 01:52 PM #4
Re: Aggregate function in SQL Server Hmhm.. that is the perfect section for this post.

Raj.
- 01-16-2009 06:12 AM #5
Re: Aggregate function in SQL Server Thank you so much for your valuable reply.
Similar Threads
-
How to use hypertext content server forms (HCSF) in stellent content server ??
By yaznesh in forum Oracle Fusion MiddlewareReplies: 6Last Post: 03-23-2010, 06:48 PM -
Connection Server : Launch Archiver for Content Server not working
By noel in forum Oracle Fusion MiddlewareReplies: 1Last Post: 02-26-2009, 06:24 AM -
How to pass parameters to a pl/sql function from Oracle Discoverer Desktop?
By Gabo86 in forum Oracle Developer Suite and ToolsReplies: 3Last Post: 02-24-2009, 09:00 AM -
DATEDIFF function in Oracle like SQL Server
By simona007 in forum SQL PL/SQLReplies: 2Last Post: 02-23-2009, 03:09 AM -
PL/SQL function to return more than one value
By oracle_new in forum SQL PL/SQLReplies: 2Last Post: 01-28-2009, 11:46 AM


LinkBack URL
About LinkBacks
Reply With Quote


