Solved

select distinct with two fields

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

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 73

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

743 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

12 Experts available now in Live!

Get 1:1 Help Now