Solved

calculated fields like where inside where

Posted on 2014-03-07
3
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 74

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 41

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

737 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