Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:26:24+00:00 2026-05-29T23:26:24+00:00

I’m currently facing an issue that my Oracle knowledge cannot solve, I’m definitely not

  • 0

I’m currently facing an issue that my Oracle knowledge cannot solve, I’m definitely not DB expert and that’s why I ask you if you have any idea how to solve my SQL query issue.

Here’s my problem, I have two tables, let’s call them DEVICE_TABLE and COUNT_TABLE

COUNT_TABLE looks like :

    DEVICE (Int) PK         |       QUANTITY (Int)
- - - - - - - - - - - - - - - - - - - - - - - - - - -
        1001                |              4
- - - - - - - - - - - - - - - - - - - - - - - - - - -
        1002                |             20
- - - - - - - - - - - - - - - - - - - - - - - - - - - 
        1003                |              1
…

DEVICE_TABLE looks like :

     ID (Int) PK            |      WiFi (String)            |     Email (String)          |   Bluetooth(String)           |   …
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        1001                |             Yes               |               No            |                 No            |   …
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        1002                |             Yes               |               Yes           |                 No            |   …
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        1003                |             Unknown           |               Unknown       |                 Yes           |   …
…

Constraints are :

DEVICE_TABLE.ID = COUNT_TABLE.DEVICE

WiFi, Email, Bluetooth… are Strings that can only be : “Yes”, “No” or “Unknown”

Finally, my SQL request result expected is (based on my example):

         Feature        |            Yes           |              No            |            Unknown          
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        WiFi            |             24           |                 0          |                 1                  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
       Email            |             20           |                 4          |                 1                  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    Bluetooth           |              1           |                24          |                 0                   
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
…

In few words, aim of this request is to sum all devices count that are compatible with a particular feature.

Thank you in advance if you have any clue on how to achieve this ! (Maybe it is not possible…)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:26:26+00:00Added an answer on May 29, 2026 at 11:26 pm

    In Oracle 11, you can use the pivot clause together with the unpivot clause:

    with 
    count_table as (
         select 1001 device_id,  4 quantity from dual union all
         select 1002 device_id, 20 quantity from dual union all
         select 1003 device_id,  1 quantity from dual 
    ),
    device_table as (
         select 1001 id, 'Yes'     wifi, 'No'       email, 'No'  bluetooth from dual union all
         select 1002 id, 'Yes'     wifi, 'Yes'      email, 'No'  bluetooth from dual union all
         select 1003 id, 'Unknown' wifi, 'Unknown'  email, 'Yes' bluetooth from dual 
    )
    ----------------------------------------
    select * from (
          select
            feature,
            yes_no_unknown,
            sum(quantity)  quantity
          from 
             count_table  c join 
             device_table d on c.device_id = d.id
          unpivot  ( yes_no_unknown
                     for feature in (wifi, email, bluetooth)
          ) 
          group by 
          feature,
          yes_no_unknown
    )  
    pivot ( sum (quantity)
            for yes_no_unknown in ('Yes' as yes, 'No' as no, 'Unknown' as unknown)
    )
    ;
    

    Alternatively, you might want to join the two existing tables to a third table that containts the values for the three desired rows. It’s probably a bit easier to read, too:

    with 
    count_table as (
         select 1001 device_id,  4 quantity from dual union all
         select 1002 device_id, 20 quantity from dual union all
         select 1003 device_id,  1 quantity from dual 
    ),
    device_table as (
         select 1001 id, 'Yes'     wifi, 'No'       email, 'No'  bluetooth from dual union all
         select 1002 id, 'Yes'     wifi, 'Yes'      email, 'No'  bluetooth from dual union all
         select 1003 id, 'Unknown' wifi, 'Unknown'  email, 'Yes' bluetooth from dual 
    )
    ----------------------------------------
    select
       f.txt,
       sum(case when ( f.txt = 'wifi'      and d.wifi      = 'Yes' ) or
                     ( f.txt = 'email'     and d.email     = 'Yes' ) or
                     ( f.txt = 'bluetooth' and d.bluetooth = 'Yes' ) 
                then   c.quantity
                else   0 end
          ) yes,
       sum(case when ( f.txt = 'wifi'      and d.wifi      = 'No' ) or
                     ( f.txt = 'email'     and d.email     = 'No' ) or
                     ( f.txt = 'bluetooth' and d.bluetooth = 'No' ) 
                then   c.quantity
                else   0 end
          ) no,
       sum(case when ( f.txt = 'wifi'      and d.wifi      = 'Unknown' ) or
                     ( f.txt = 'email'     and d.email     = 'Unknown' ) or
                     ( f.txt = 'bluetooth' and d.bluetooth = 'Unknown' ) 
                then   c.quantity
                else   0 end
          ) unknown
    from 
       count_table  c                                   join 
       device_table d on c.device_id = d.id     cross   join
       (
            select 'wifi'      txt from dual union all
            select 'email'     txt from dual union all
            select 'bluetooth' txt from dual
       ) f
    group by 
        f.txt;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently facing an issue, I have a method that I run which
I'm looking for some input for a challenge that I'm currently facing. I have
I am facing strange issue. I have wep-part that reads data from user's profile.
I'm currently facing the following issue: My app dynamically creates images (320 x 480
Currently I am facing an issue with my Makefile caused by evaluation of a
The current issue I'm facing is this. I have a directory as such webroot:banners/users/
I have a java application running on Linux system. Currently we are facing some
I am designing a web application in Flex 4 and currently facing an issue
I am currently facing a problem that is concerning the google search, curl and
I am currently facing an issue with the PHP SDK's getLogoutURL function. The function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.