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 8036751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:43:23+00:00 2026-06-05T02:43:23+00:00

I have an SQL query which works fine in DB2 My result is SERVICE

  • 0

I have an SQL query which works fine in DB2
My result is

SERVICE   IN   OUT   INPROGRESS

ADSL      1     5      10
VOIP      15    12     11
IPTV      20    14     17

Now I want to transform it to be like this:

CLASS       ADSL   VOIP   IPTV

IN           1     5      10
OUT          15    12     11
INPROGRESS   20    14     17

Although it seems long my SQL is very simple but I never had transformed this. If someone knows I will be thankful.

My SQL is

select  distinct 'ADSL' as SERVICE,

(select count(*) as In from ticket 
where 
(class='C1'  and
(servicesinfault='25'))),

(select count(*) as Out from ticket
where 
(class='C2' and
(servicesinfault='25'))),


(select count(*) as In_progress from ticket
where 
(class='C3' and
(servicesinfault='25')))

from ticket where servicesinfault = '25'

union all

select  distinct 'VoIP',

(select count(*) from ticket 
where
(class='C1'  and
(servicesinfault='26'))),

(select count(*) from ticket
where
(class='C2'  and
(servicesinfault='26'))),


(select count(*) from ticket
where 
(class='C3'  and
(servicesinfault='26')))

from ticket where servicesinfault = '26'

union all

select  distinct 'IPTV',

(select count(*) from ticket 

where 
(class='C1'  and
(ticket.servicesinfault='27'))),

(select count(*) from ticket
where 
(class='C2'  and
(servicesinfault='27'))),

(select count(*) from ticket
where 
(class='C3'  and
(servicesinfault='27')))

from ticket where servicesinfault = '27'
  • 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-06-05T02:43:24+00:00Added an answer on June 5, 2026 at 2:43 am

    Just as a remark, your result should like:

    CLASS       ADSL   VOIP   IPTV
    
    IN           1     15     20
    OUT          5     12     14
    INPROGRESS   10    11     17
    

    The pivoted version should be something like:

    select distinct 'In' as CLASS,
    
                    (select count(*) as 'ADSL'
                       from ticket
                      where (class = 'C1' and (servicesinfault = '25'))),
    
                    (select count(*) as 'VoIP'
                       from ticket
                      where (class = 'C1' and (servicesinfault = '26'))),
    
                    (select count(*) as 'IPTV'
                       from ticket
                      where (class = 'C1' and (servicesinfault = '27')))
    
      from ticket
     where class = 'C1'
    
    union all
    
    select distinct 'Out',
    
                    (select count(*)
                       from ticket
                      where (class = 'C2' and (servicesinfault = '25'))),
    
                    (select count(*)
                       from ticket
                      where (class = 'C2' and (servicesinfault = '26'))),
    
                    (select count(*)
                       from ticket
                      where (class = 'C2' and (servicesinfault = '27')))
    
      from ticket
     where class = 'C2'
    
    union all
    
    select distinct 'InProgress',
    
                    (select count(*)
                       from ticket
    
                      where (class = 'C3' and (ticket.servicesinfault = '25'))),
    
                    (select count(*)
                       from ticket
                      where (class = 'C3' and (servicesinfault = '26'))),
    
                    (select count(*)
                       from ticket
                      where (class = 'C3' and (servicesinfault = '27')))
    
      from ticket
     where class = 'C3'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using php, i have a sql query which works fine, dateentry only has the
Right now I have this SQL query which is valid but always times out:
I have written a MDX query which works fine in SQL Server Management Studio.
I have a SQL query with a left join which works fine: SELECT book.*
I have the following which works in SQL Query Analyzer . select oh.* from
I have the following HQL query which works fine, however it returns a list
I have the following query which works fine with MySQL but refuses to work
I have an SQL LIKE query running on mySQL which runs fine on my
I have SQL query which joins 3 tables, one being just a many-to-many connecting
I have an SQL query which is working ok to an extent. The LEFT

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.