• Register
0 votes
266 views

Problem :

My stored procedure giving me following error

cannot perform an aggregate function on an expression containing an aggregate or a subquery.

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

You can move the your logic for SUM() inside the subquery as follows:

SELECT t.col_1, t.col_2,
       (SELECT COUNT(*)
        FROM table_prods p
        WHERE t.col_2 <> p.prod
       ) as Total
FROM my_table t
WHERE t.is_rated = '1'
GROUP BY t.col_1, t.col_2 ;
This will surely resolve your issue.
9 7 4
38,600 points

Related questions

1 vote
1 answer 14 views
14 views
Problem : The Query works fine under Sybase, but gives the error in the title of this post when executed under SQL Server.General outline of the query is: select sum ( t.graduates - ( select sum ( t1.graduates ) from table as t1 where t1 ... : SQL Server &ldquo;cannot perform an aggregate function on an expression containing an aggregate or a subquery&rdquo; Any suggestions would be appreciated.
asked Mar 30 Sabbir Hossain 14.6k points
0 votes
1 answer 9 views
9 views
Problem: Any solution to this issue > If you delete a stored procedure, function, or trigger and then create it again
asked Apr 28 ummeshani 10.8k points
0 votes
1 answer 25 views
25 views
Problem I am working on some query for my project and the requirement is to show the second value. For sake of example, say I have salary table in Microsoft SQL Server and I need fetch the second maximum salary. I am not too experienced in T-SQL, I used the ... So I sow there is RANK() function in T-SQL, but I do not completely understand how it works. Any suggestions will very appreciated.
asked Dec 17, 2020 alexh 2.6k points
1 vote
1 answer 5 views
5 views
Problem: Database connection is missing and Iget this message: Database connection mysql is missing or could not be created.
asked Apr 25 PkGuy 23.5k points
0 votes
1 answer 19 views
19 views
Problem: Any solution to this issue > Bulk load data conversion error (type mismatch or invalid character for the specified codepage)
asked Apr 22 ummeshani 10.8k points
0 votes
1 answer 23 views
23 views
Problem: I get the following red-warning message on the screen Text was truncated or one or more characters had no match on the target code page What am I doing wrong? Thank you
asked Mar 21 ummesalma 29.2k points
0 votes
1 answer 31 views
31 views
Problem column name or number of supplied values does not match table definition
asked Feb 9 charles mathews 5.5k points
0 votes
2 answers 1K views
1K views
Problem : I want to import the flat file into my oledb target sql server database. But I am getting below error message : [Source - 18942979103_txt [424]] Error: Data conversion failed. The data conversion for column "recipient-name" returned status value 4 and status text ... more characters had no match in the target code page.". Why am I getting this error message? What am I doing wrong here?
asked Dec 23, 2019 alecxe 7.5k points
0 votes
1 answer 18 views