Solved

Finding Usage Overlap

Posted on 2014-04-10
2
220 Views
Last Modified: 2014-04-10
Hello EE,

I have a set of usage data that I need to group by unique usage.  For example in my data, I need to know how many customer are contacting the help desk by using phone and mail format. In my data I can have customer who are using both mail and phone, phone only or mail only.  In the attached example, I need to group my data like below

Mail_Only        Phone_Only      Phone_Mail
     21                    2                      3

The data is in the data tab

Thanks in advance for your help
testdata.xlsx
0
Comment
Question by:fb1990
2 Comments
 
LVL 34

Accepted Solution

by:
johnsone earned 500 total points
ID: 39993184
This query gave me the results you were looking for.

SELECT SUM(CASE 
             WHEN phone_cnt = 0 
                  AND mail_cnt > 0 THEN 1 
             ELSE 0 
           END) mail_only, 
       SUM(CASE 
             WHEN phone_cnt > 0 
                  AND mail_cnt = 0 THEN 1 
             ELSE 0 
           END) phone_only, 
       SUM(CASE 
             WHEN phone_cnt > 0 
                  AND mail_cnt > 0 THEN 1 
             ELSE 0 
           END) phone_mail 
FROM   (SELECT pool_id, 
               SUM(CASE device 
                     WHEN 'Phone' THEN 1 
                     ELSE 0 
                   END) phone_cnt, 
               SUM(CASE device 
                     WHEN 'Mail' THEN 1 
                     ELSE 0 
                   END) mail_cnt 
        FROM   tbl1 
        GROUP  BY pool_id) cnt_data; 

Open in new window

0
 
LVL 1

Author Closing Comment

by:fb1990
ID: 39993349
Sweet!  Thank you so much!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

770 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