Programmers learn & share
0 votes
89 views

Problem :

My stored procedure giving me following error

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

by (6.9k points)   | 89 views

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.
by (36.1k points)  
2,204 questions
2,606 answers
59 comments
241 users