calculated fields like where inside where

Hi,

I have the following table

TABLES DESCRIPTIONS
The table is in a database table. I need a query that produces the second table, that is a resume of the first table, any idea?
LVL 1
joyacv2Asked:
Who is Participating?
 
sdstuberConnect With a Mentor Commented:
SELECT category,
       COUNT(*) quantity,
       COUNT(CASE WHEN TYPE = 'P' THEN 1 END) type_p,
       COUNT(CASE WHEN TYPE = 'T' THEN 1 END) type_t
  FROM your_table
GROUP BY category
0
 
SharathData EngineerCommented:
try this
SELECT CATEGORY,TYPE_P+TYPE_T AS Quantity,TYPE_P,TYPE_T 
  FROM (SELECT *
          FROM test
         PIVOT (COUNT(TYPE1) FOR TYPE1 IN ('P' as TYPE_P,'T' as TYPE_T)) P1) T1

Open in new window

http://sqlfiddle.com/#!4/bcf20/11
0
 
joyacv2Author Commented:
exactly what I am looking for!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.