title: Use of sum and count inside a case statement in sql
body: <pre><code>select req.code ,res.code,
  case
  ( 
  when (req.code==res.code) then 'pass'
  when (req.code&lt;&gt;res.code) then 'fail'
  /*....2 more case 'when' 'then' statements here*/
  end ) result,
  
  req.country ,res.country,
  
  case (when then staments as above)result,
  /*.......case stmts upto 70 statemnts*/
  from requesttable req full outer join responsetable res on
  req.id=res.id 
  and ....some conditions.
  </code></pre>
  
  <p>Can anyone tell me how can I sum every column and display the sum as well as the count of records in every column of both tables simultaneously and display count in my query?</p>
  
  <p>My result should be of this sort</p>
  
  <pre><code>code  code1  result  sum     sum1    equivalence country country1 result1  sum    sum1
  100   100    pass    200000  25000   fail        ind     aus      fail     800000 800000
  
  equivalence
  pass
  </code></pre>
  
  <p>I am trying to prepare a report joining two tables. I am using multiple case statements to accomplish this. I want to display sum of each column and count of each column of both the tables together in a single report. The query that I have is of the following type.</p>