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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:16:51+00:00 2026-06-14T07:16:51+00:00

I apologize in advance since I am somewhat new to SQL so my code

  • 0

I apologize in advance since I am somewhat new to SQL so my code may seem like it makes no sense at all, but I will try to make as much sense of it as I can and hopefully you more experienced people can help me out. I’m not sure if it will help, but I am using an Oracle database.

I have two tables:

Elements – This contains an elementID as well as an elementName field
Exchanges – This contains an exchangeID and an elementID field

I created the following query in order to retrieve only the elements that occur in more than 50% of the exchanges:

SELECT e.elementName
FROM Elements e
WHERE e.elemID in
(SELECT elemID FROM Exchanges
GROUP BY elemID
HAVING (count(*) / (SELECT count(*) FROM
(SELECT exchangeID, count(*) FROM Exchanges GROUP BY exchangeID))) > 0.5);

This part seems to be working fine, but I ALSO need to retrieve the % of occurrences for each item in exchanges. So, for example, if an element A occurs in 76% of exchanges and an element B occurs in 59% of exchanges, I would want to return a row with A and 76% and another row with B and 59%. In my mind, this would mean somehow getting the result of the expression on the left side of the HAVING clause:

(count(*) / (SELECT count(*) FROM
(SELECT exchangeID, count(*) FROM Exchanges GROUP BY exchangeID)))

This expression gives me the percentage I am looking for, but I haven’t been able to figure out a way to use this expression in such a way that I can retrieve it with a SELECT so that I can pair it up with its corresponding elementName in a way like I just explained.

Is there a way to propagate this value up to my SELECT so that I can retrieve the value I am looking for?

  • 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-14T07:16:52+00:00Added an answer on June 14, 2026 at 7:16 am

    You will want to pre-aggregate two derived tables (1) the exchanges per-element, and (2) the total number of exchanges. The rest become elementary.

        SELECT x.elementName, A.elemExchanges/B.totalExchanges Percentage
          FROM
    (
        SELECT x.elemID,
               count(distinct x.exchangeID) elemExchanges
          FROM Exchanges x
      GROUP BY x.elemID
    ) A
    CROSS JOIN
    (
        SELECT COUNT(distinct y.exchangeID) totalExchanges
          FROM Exchanges y
    ) B
          JOIN Elements e on e.elemID = A.elemID
         WHERE A.elemExchanges/B.totalExchanges > 0.5;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem like a fairly basic question, for which I apologise in advance.
I apologize in advance, if this question doesn't make sense. I'm a newbie. I
I will apologize in advance as this post is born out of severe frustration.
I am new to Ext so I apologize in advance if my question is
I apologize in advance for a newbie question, but why do I get Access
I apologize in advance for the open-ended question. I tried searching, but wasn't sure
First off, I'd like to apologize in advance for not knowing this. I've been
[I apologize in advance for the complexity of the problem... but what good problem
I apologize in advance for the long-winded question but I wanted to make sure
I am relatively new to perl and I apologize in advance if this question

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.