• Register
0 votes
155 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

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

0 votes
2 answers 232 views
232 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
2 answers 89 views
89 views
Problem : I am new to the SQL. What am I doing wrong here? SELECT LEFT(SUBSTRING(batchinfo.datapath, PATINDEX('%[0-9][0-9][0-9]%', batchinfo.datapath), 8000), PATINDEX('%[^0-9]%', SUBSTRING(batchinfo.datapath, PATINDEX('%[0-9][0-9][0-9]%',batchinfo. ... I am trying to do group by the first, second, and third columns having the max rid. It is works perfectly fine without the group by and having.
asked Nov 27, 2019 alecxe 7.5k points
0 votes
1 answer 5 views