sql server - SQL Error of Cannot perform an aggregate function on an expression containing an aggregate or a subquery -


i executing query in sql giving me error "cannot perform aggregate function on expression containing aggregate or sub query." there can me it. stuck. thank here query.

select [id]       ,[name]       ,sum(case             when [code] = 1              case               when exists(select * [sampletab] [id] = [id]and [code] = 2)                  case when exists(select * [sampletab] [id] = [id] , [code] = 4) 100                  else 100                 end                  else 100                end                when [code] = 8 200            when code = 2 100            when code = 4 100        end       ) "totl"    [test].[dbo].[sampletab]   group id , name 

my data

here's version of query should results.

select id, name, sum(scorepercode) (     select      id,     name,     case when code = 1 100         when code = 2 50         when code = 4 20         when code = 8 200         end scorepercode     [test].[dbo].[sampletab] ) x group id, name 

this section of query meaningless, , source of problems. you're going arrive @ value of 100, if query ever stood chance of working...

 when [code] = 1                       case when exists ( select * [sampletab] [code] = 2 )                               case when exists ( select * [sampletab] [code] = 4)                  100                 else 100 end              else 100 end 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -