Solved

Finding Usage Overlap

Posted on 2014-04-10
2
218 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.

Join & Write a Comment

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

744 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