Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

select distinct with two fields

Posted on 2014-03-07
5
Medium Priority
?
515 Views
Last Modified: 2014-03-07
Hi,

I have the following situation

TABLE DESCRIPTION
I THINK THIS IS LIKE A SELECT DISTINCT OR SOMETHING ELSE, ANY IDEA?
0
Comment
Question by:joyacv2
  • 3
  • 2
5 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 39913660
it would help if you posted data in text form
images aren't usable
0
 
LVL 1

Author Comment

by:joyacv2
ID: 39913665
Ok give some minutes
0
 
LVL 1

Author Comment

by:joyacv2
ID: 39913673
table 1

cat1 cat2      type
A2      MOS      T
A2      MOS      P
BT      MOS      P
A2      GH              T
BT      CH              P

Table desired
cat1 cat2     Quan T-T   T-P
A2      MOS      2      1      1
A2      GH              1      1      0
BT      MOS      1      0      1
BT      CH              1      0      1
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 39913692
same idea as previous question, but you need to extend the group by
and order it


SELECT category cat1,
       cat cat2,
       COUNT(*) quantity,
       COUNT(CASE WHEN TYPE = 'P' THEN 1 END) type_p,
       COUNT(CASE WHEN TYPE = 'T' THEN 1 END) type_t
  FROM yourtable
GROUP BY category, cat
ORDER BY cat1, cat2 DESC;
0
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 39913707
perfect, i understand the concept!!!! Thanks!!!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This article discusses how to implement server side field validation and display customized error messages to the client.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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…
Suggested Courses

877 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