• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

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?
0
joyacv2
Asked:
joyacv2
1 Solution
 
sdstuberCommented:
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now