Solved

select distinct with two fields

Posted on 2014-03-07
5
513 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

636 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