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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:42:49+00:00 2026-06-01T11:42:49+00:00

What is the best and simplets way to save two values from two different

  • 0

What is the best and simplets way to save two values from two different select statements?

I have a query that’s like this:

SELECT * FROM (
SELECT FIELD1 FROM (<SUB SELECT STATMENT>)
UNION ALL
SELECT FIELD2 FROM (<SUB SELECT STATMENT>)) 

What I’d like is to save the value from FIELD1 and FIELD2 so later I can do some calulation with it, such as FIELD1 / FIELD2. I tried using a cursor but ran into issues. And it’s too complicated for select statement. Any suggestions?

UPDATE:

The result set from my current query looks like this.

SUM_OF_MESSAGES  | LABEL
----------------------------
      145323     | PUSHED
      2633267    | RECEIVED
                 |

I’d like to take the values from the first two rows and divide them. Eg. 145323 / 2633267

In other words, is there a way to divide FIELD1 by FIELD2 from my above query?

ANOTHER UPDATE:

Here is my query:

SELECT SUM(R.MESSAGES) AS SUM_OF_MESSAGES, CASE WHEN R.LABEL = 1 THEN 'PUSHED' WHEN R.LABEL = 2 THEN 'RECEIVED' END AS LABEL FROM (                
SELECT SUM(Q.MESSAGES) AS "MESSAGES", 1 LABEL FROM (
SELECT USER_LOGIN,
                 EVENT_MSG,
                 ROW_LST_UPD_TS,
                 COMPONENT_NAME,
                 REGEXP_SUBSTR (SUBSTR (EVENT_MSG, INSTR (EVENT_MSG, ' ', 1, 1), INSTR (EVENT_MSG, ' ', 1, 1)), '[0-9]+') AS "MESSAGES"
            FROM EVENT_MGT.EVENT_LOG
            WHERE ROW_LST_UPD_TS BETWEEN (TRUNC (:DATEINPUT) - 1) + 5 / 86400 AND (TRUNC (:DATEINPUT)) + 5 / 86400
                 AND EVENT_ID = 101
                 AND COMPONENT_NAME LIKE '%Web ICE Downloader.exe%'
        GROUP BY COMPONENT_NAME,
                 USER_LOGIN,
                 EVENT_MSG,
                 ROW_LST_UPD_TS
                 ORDER BY ROW_LST_UPD_TS ) Q         
UNION ALL           
SELECT SUM(Q.MESSAGES) "MESSAGES", 2 LABEL FROM (
SELECT USER_LOGIN,
                 EVENT_MSG,
                 ROW_LST_UPD_TS,
                 COMPONENT_NAME,
                 REGEXP_SUBSTR (SUBSTR (EVENT_MSG, INSTR (EVENT_MSG, ' ', 1, 1), INSTR (EVENT_MSG, ' ', 1, 1)), '[0-9]+') AS "MESSAGES"
            FROM EVENT_MGT.EVENT_LOG
            WHERE ROW_LST_UPD_TS BETWEEN (TRUNC (:DATEINPUT) - 1) + 5 / 86400 AND (TRUNC (:DATEINPUT)) + 5 / 86400
                 AND EVENT_ID = 100
                 AND COMPONENT_NAME LIKE '%Web ICE Downloader.exe%'
        GROUP BY COMPONENT_NAME,
                 USER_LOGIN,
                 EVENT_MSG,
                 ROW_LST_UPD_TS
                 ORDER BY ROW_LST_UPD_TS ) Q ) R
                 GROUP BY  R.LABEL

Here is my result set:

SUM_OF_MESSAGES  | LABEL
----------------------------
      145323     | PUSHED
      2633267    | RECEIVED
                 |

I’d like to divide the two numbers in the same select statement. Please help.

  • 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-01T11:42:50+00:00Added an answer on June 1, 2026 at 11:42 am

    It seems like you would only need one query with a bit of logic in your aggregates

          SELECT COUNT( CASE WHEN event_id = 100 
                             THEN q.messages
                             ELSE null
                         END) Received,
                 COUNT( CASE WHEN event_id = 101
                             THEN q.messages 
                             ELSE null
                         END) Pushed,
                 COUNT( CASE WHEN event_id = 101
                             THEN q.messages 
                             ELSE null
                         END) /
                    COUNT( CASE WHEN event_id = 100 
                               THEN q.messages
                               ELSE null
                           END) Pushed_Over_Received
            FROM (
              SELECT USER_LOGIN,
                     EVENT_ID,
                     EVENT_MSG,
                     ROW_LST_UPD_TS,
                     COMPONENT_NAME,
                     REGEXP_SUBSTR (SUBSTR (EVENT_MSG, INSTR (EVENT_MSG, ' ', 1, 1), 
                     INSTR (EVENT_MSG, ' ', 1, 1)), '[0-9]+') AS "MESSAGES"
                FROM EVENT_MGT.EVENT_LOG
                WHERE ROW_LST_UPD_TS BETWEEN (TRUNC (:DATEINPUT) - 1) + 5 / 86400 
                                         AND (TRUNC (:DATEINPUT)) + 5 / 86400
                  AND EVENT_ID in( 100, 101 )
                  AND COMPONENT_NAME LIKE '%Web ICE Downloader.exe%'
            )
    

    Alternately, you could do something like this with analytic functions (you’d want to replace the subquery t in my query with the query you’ve written that produces the two rows of output)

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (
      2    select 145323 sum_of_messages, 'PUSHED' label from dual
      3    union all
      4    select 2633267, 'RECEIVED' from dual
      5  )
      6  select sum_of_messages,
      7         label,
      8         round( 100*ratio_to_report(sum_of_messages) over (), 2) pct_of_messages
      9*   from t
    SQL> /
    
    SUM_OF_MESSAGES LABEL    PCT_OF_MESSAGES
    --------------- -------- ---------------
             145323 PUSHED              5.23
            2633267 RECEIVED           94.77
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Best to describe this in code... I have this public class A<T> { public
Does anyone have any suggestions for the best / simplest way to view all
I create a txt file that have 3 element and i wrote this code
What is the best/simplest way to detect if a queue I have created is
I've an application that creates messages formatted using JSON. What's the simplest/best way to
What is the best way to create a view for a single control that
I'm wondering what is the best (fastest and simplest) way to have a textfield
What would be the best, most portable, simplest way to create a GUI-like feeling
What's the best and simplest way to save a webpage displayed with QWebView() to
What do you think is the best way of writing this method for calculating

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.