Solved

select distinct with two fields

Posted on 2014-03-07
5
512 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
[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
  • 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 500 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

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
The viewer will learn how to count occurrences of each item in an array.

734 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