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

  • Home
  • SEARCH
  • 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 9157355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:59:40+00:00 2026-06-17T12:59:40+00:00

I’ve got a bit of a complicated query that I’m struggling with. You will

  • 0

I’ve got a bit of a complicated query that I’m struggling with. You will notice that the schema isn’t the easiest thing to work with but it’s what I’ve been given and there isn’t time to re-design (common story!).

I have rows like the ones below. Note: The 3 digit value numbers are just random numbers I made up.

id     field_id     value
1      5            999 
1      6            888
1      7            777
1      8            foo <--- foo so we want the 3 values above
1      9            don't care

2      5            123 
2      6            456
2      7            789
2      8            bar <--- bar so we DON'T want the 3 values above
2      9            don't care

3      5            623 
3      6            971
3      7            481
3      8            foo <--- foo so we want the 3 values above
3      9            don't care

...
...

n      5            987 
n      6            654
n      7            321
n      8            foo <--- foo so we want the 3 values above
n      9            don't care

I want this result:

id     result
1      999*888*777
3      623*971*481
...
n      987*654*321

Is this clear? So we have a table with n*5 rows. For each of the sets of 5 rows: 3 of them have values we might want to multiply together, 1 of them tells us if we want to multiply and 1 of them we don’t care about so we don’t want the row in the query result.

Can we do this in Oracle? Preferably one query.. I guess you need to use a multiplication operator (somehow), and a grouping.

Any help would be great. Thank you.

  • 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-17T12:59:41+00:00Added an answer on June 17, 2026 at 12:59 pm

    something like this:

    select m.id, exp(sum(ln(m.value)))
      from mytab m
     where m.field_id in (5, 6, 7)
       and m.id in (select m2.id
                      from mytab m2
                     where m2.field_id = 8
                       and m2.value = 'foo')
     group by m.id;
    

    eg:

    SQL> select * from mytab;
    
            ID   FIELD_ID VAL
    ---------- ---------- ---
             1          5 999
             1          6 888
             1          7 777
             1          8 foo
             1          9 x
             2          5 123
             2          6 456
             2          7 789
             2          8 bar
             2          9 x
             3          5 623
             3          6 971
             3          7 481
             3          8 foo
             3          9 x
    
    15 rows selected.
    
    SQL> select m.id, exp(sum(ln(m.value))) result
      2    from mytab m
      3   where m.field_id in (5, 6, 7)
      4     and m.id in (select m2.id
      5                    from mytab m2
      6                   where m2.field_id = 8
      7                     and m2.value = 'foo')
      8   group by m.id;
    
            ID     RESULT
    ---------- ----------
             1  689286024
             3  290972773
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
This could be a duplicate question, but I have no idea what search terms

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.