Solved

calculated fields like where inside where

Posted on 2014-03-07
3
321 Views
Last Modified: 2014-03-07
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
Comment
Question by:joyacv2
3 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39913556
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
 
LVL 40

Expert Comment

by:Sharath
ID: 39913601
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
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 39913634
exactly what I am looking for!!!!
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This article discusses how to create an extensible mechanism for linked drop downs.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
The viewer will learn how to dynamically set the form action using jQuery.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now