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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:56:49+00:00 2026-05-28T07:56:49+00:00

I have been looking over the web but have not come across an answer

  • 0

I have been looking over the web but have not come across an answer to my problem. The closest I found was this also from StackOverflow.

So what I have is transactions with different statuses. I am trying to compile a query that will summarize all transactions according to their status. I can easily do that with a Group By, but what I need and can’t do is to sum two of the particular statuses. For example:

Status 
--------
Status_A
Status_B
Status_C_D
Status_C
Status_D
Status_E

Status_C_D above would be the sum of Status_C and Status_D. In case you are wondering, status C is a kind of transaction error, and Status_D is another kind of error, so they want the sum of both to easily see the total of transactions with errors (everything will be shown on a report). What I have is this:

SELECT DECODE(STATUS_CD, 
         0, 'Status_A',
         1, 'Status_B',
         2, 'Status_C',
         3, 'Status_D',
         4, 'Status_E',
         'Unknown') status
FROM table_a ...

Hopefully that’s enough context. Any help is much appreciated. 🙂

select decode(TABLE_A.status_cd, 0,  'Status A',
                                 1, 'Status B',
                                 2, 'Status C',
                                 3, 'Status D',
                                 4, 'Status E',
                                 'Unknown') status, 
        SUM(decode(trunc(((sysdate - TABLE_A.date_time) +8) / 8), 1, 1, 0)) "0-7",
        SUM(decode(trunc(((sysdate - TABLE_A.date_time) +8) / 8), 2, 1, 0)) "8-15",
        SUM(decode(trunc(((sysdate - TABLE_A.date_time) +8) / 8), 3, 1, 0)) "16-23",
        SUM(decode(trunc(((sysdate - TABLE_A.date_time) +9) / 8), 4, 1, 0)) "24-30",
        SUM(decode(trunc(((sysdate - TABLE_A.date_time) -1) / 30), 1, 1, 0)) "31-60",
        SUM(decode(trunc(((sysdate - TABLE_A.date_time) -1) / 30), 2, 1, 0)) "61-90",
        SUM(decode(trunc(((sysdate - TABLE_A.date_time) -1) / 30), 3, 1, 0)) "91-120",
        SUM(decode(trunc(((sysdate - TABLE_A.date_time) -1) / 60), 2, 1, 0)) "121-180",
        SUM(decode(trunc(((sysdate - TABLE_A.date_time)) / 181), 0, 0, 1)) ">180"
FROM Table_A
WHERE ...
GROUP BY TABLE_A.status_cd
  • 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-28T07:56:49+00:00Added an answer on May 28, 2026 at 7:56 am

    Assuming you are happy to see these summaries across the page, the simplest way to do this would be:

    select sum(DECODE(STATUS_CD, 0,1, 0)) Status_A,
           sum(DECODE(STATUS_CD, 1,1, 0)) Status_B,
           sum(DECODE(STATUS_CD, 2,1, 3,1, 0)) Status_C_D,
           sum(DECODE(STATUS_CD, 2,1, 0)) Status_C,
           sum(DECODE(STATUS_CD, 3,1, 0)) Status_D,
           sum(DECODE(STATUS_CD, 4,1, 0)) Status_E
    FROM table_a ...
    

    EDIT: If you need to see the results down the page, try:

    select "status", 
            SUM(decode(trunc(((sysdate - "date_time") +8) / 8), 1, 1, 0)) "0-7",
            SUM(decode(trunc(((sysdate - "date_time") +8) / 8), 2, 1, 0)) "8-15",
            SUM(decode(trunc(((sysdate - "date_time") +8) / 8), 3, 1, 0)) "16-23",
            SUM(decode(trunc(((sysdate - "date_time") +9) / 8), 4, 1, 0)) "24-30",
            SUM(decode(trunc(((sysdate - "date_time") -1) / 30), 1, 1, 0)) "31-60",
            SUM(decode(trunc(((sysdate - "date_time") -1) / 30), 2, 1, 0)) "61-90",
            SUM(decode(trunc(((sysdate - "date_time") -1) / 30), 3, 1, 0)) "91-120",
            SUM(decode(trunc(((sysdate - "date_time") -1) / 60), 2, 1, 0)) "121-180",
            SUM(decode(trunc(((sysdate - "date_time")) / 181), 0, 0, 1)) ">180"
    from
    (SELECT DECODE(coalesce(d.dummy_status, a.STATUS_CD), 
             'X', 'Status_C_D'
             '0', 'Status_A',
             '1', 'Status_B',
             '2', 'Status_C',
             '3', 'Status_D',
             '4', 'Status_E',
             'Unknown') "status",
             a."date_time"
     FROM table_a a
     LEFT JOIN (select '2' status_cd, '2' dummy_status from dual union
                select '2' status_cd, 'X' dummy_status from dual union
                select '3' status_cd, '3' dummy_status from dual union
                select '3' status_cd, 'X' dummy_status from dual) d
            ON a.status_cd = d.status_cd
     ...
    ) group by "status"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking over the internet for a while about this, but it
I have been looking over this code for the past hour, I cant see
I have been looking at the feasibility of porting over an intranet web app
I've been looking all over for a simple example of how to have an
I have been looking at metrics for coupling and also look at DSM .
I'm not sure if 'architecture' is the correct term, but I've been looking for
This is by far the weirdest problem I've been stuck with. I have a
Have been looking at the MVC storefront and see that IQueryable is returned from
I have been looking into IKVMing Apache's FOP project to use with our .NET
We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance

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.