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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:18:38+00:00 2026-06-11T00:18:38+00:00

I have a table that I’d like to run some calculations on but this

  • 0

I have a table that I’d like to run some calculations on but this select statement is above my oracle wheelhouse.

I wanted to attempt (as much of this) in oracle. But ultimately this will end up getting run through php to get output to the screen.

This is for Oracle 8i

I have 4 important pieces of data – (Customer Id, New_Item, Suggested_net, and Volume by year)

customer_id = #
new_item = 0 or 1
suggested_net = #
year_1_n =  #
year_2_n =  #
year_3_n =  #
year_1_e =  #
year_2_e =  #
year_3_e =  #

new_items = 0 correlates only to year_1_e, year_2_e, year_3_e

new_items = 1 correlates only to year_1_n, year_2_n, year_3_n

Here’s an example

customer_id, new_item, suggested_net, year_1_n, year_2_n, year_3_n, year_1_e, year_2_e, year_3_e

2, 0, 4.25, null, null, null, 100, 100, 100;
2, 0, 5.25, null, null, null, 100, 100, 100;
3, 0, 2.50, null, null, null, 100, 100, 100;
1, 0, 3.50, null, null, null, 100, 100, 100;
2, 1, 5.99, 100, 200, 300, null, null, null;
3, 1, 4.99, 200, 400, 600, null, null, null;

So I need to get this info:
For each row, add the volumes up (year_x…) * suggested_net, Then add that amount to a grouped customer_id by new_item = 0 or 1.

So using the above table

Customer 2, new_item = 0 would have a sum of (1275 + 1575)
Customer 1, new_item = 0 would have a sum of 1050
Customer 2, new_item = 1 would have a sum of 3594

etc. etc.

Now this may or may not be possible or efficient to do in a select statement, but like I said I wanted to do as much of the heavy lifting with oracle, the rest I can handle with php.

  • 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-11T00:18:39+00:00Added an answer on June 11, 2026 at 12:18 am
    SELECT Coustomer_Id,
           new_item,
           SUM((CASE WHEN new_item = 1 THEN year_1_n + year_2_n + year_3_n 
                     WHEN new_item = 0 THEN year_1_e + year_2_e + year_3_e
                END ) * suggested_net) AS TotalSum
      FROM Table1
     GROUP BY Coustomer_Id,
           new_item
    

    OR

    SELECT Coustomer_Id,
           new_item,
           SUM(DECODE(new_item, 1, year_1_n + year_2_n + year_3_n 
                              , 0, year_1_e + year_2_e + year_3_e
                              , 0) * suggested_net) AS TotalSum
      FROM Table1
     GROUP BY Coustomer_Id,
              new_item
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that looks like this: id value AGA 0.211 AGA 0.433
I have a table that looks like this: CREATE TABLE foobar ( id SERIAL
I have a table that looks like this: ID (pk,int) Col1 (nvarchar) Col2 (nvarchar)
I have a table that looks like this: ID |Name |Parent 1 |A |NULL
I Have a table that looks something like this: ComputerID | Free_Space | Disk_Size
I have a table that looks like this <table cellpadding=1 cellspacing=0 width=100% border=0> <tr>
I have table (call it my_table ) that can be simplified like this: NAME,
I have a table that was created using this mysql statement below. CREATE TABLE
I have a table that looks something like this. EDIT - I re-extracted code.
I have a table that looks like this CREATE TABLE `purchases` ( `id` INT(10)

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.