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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:19:08+00:00 2026-06-15T08:19:08+00:00

I have a problem with one of my queries in SQLPLUS. I have been

  • 0

I have a problem with one of my queries in SQLPLUS.

I have been asked to display the SuppCode, SuppName, and PostCode for all suppliers who satisfy the following contraints: Every stock item they supply has a price which is greater than the average of all stock items.

The three tables I’m working with are; Supppliers and Stocks and SupplyItems.

The Suppliers table looks looks like:

SUPPCODE SUPPNAME STREET TOWN COUNTRY POSTCODE TELNO FAXNO

With 8 seperate sample data (8 suppliers), and no null fields.

The Stocks table looks like:

ITEMNO STORECODE ITEMDESC QUANTITY UNITS REORDER PRICE SUPPCODE

With 40 seperate sample data (40 stock items), and no null fields.

The SupplyItems table looks like:

SUPPCODE CATNO STOCKNO PRICE

With 60 seperate sample data (60 supply items), and no null fields.

I have written the following query:

select distinct SU.SuppCode, Su.SuppName, PostCode
from Suppliers SU
LEFT JOIN SupplyItems SI ON SU.SuppCode = SI.SuppCode
where Price >
(select AVG(Quantity) from Stocks ST
where SI.StockNo = ST.StockNo);

I get the following output (4 values):

SUPPCODE SUPPNAME POSTCODE
S6       BSS LTD. B10 8SS
S2       ITX LTD. IT5 3TX
S3       FFG LTD. FY9 6FG
S4       OMM LTD. OM5 4MM

Now, I have been made aware that the output should contain either 2 or 3 records, so my query is wrong, though I can’t see why.

Any help would be appreciated.

  • 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-15T08:19:10+00:00Added an answer on June 15, 2026 at 8:19 am

    This:

    where Price >
    (select AVG(Quantity) from Stocks ST
    

    looks wrong – shouldn’t it rather be

    AVG(price)
    

    ?

    EDIT: also,

    select distinct SU.SuppCode, Su.SuppName, PostCode
    from Suppliers SU
    LEFT JOIN SupplyItems SI ON SU.SuppCode = SI.SuppCode
    where Price > ...
    

    probably doesn’t do what you want – this will return all suppliers who offer at least one item whose price is above the average; to get the suppliers that offer only items with price above the average, you’ll have to use a different approach, e.g. (untested)

    select distinct SU.SuppCode, Su.SuppName, PostCode
    from Suppliers SU
    where not exists (
      select null from SupplyItems si 
      where su.SuppCode = si.SuppCode
      and su.price <= (
          select AVG(price) from Stocks ST
          where SI.StockNo = ST.StockNo)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem to get to SQL queries into one, the problem is
First of all, sorry for my bad English... I have a problem with one
I have one problem with sql queries in one of my projects. Actually, I
I have a big problem with combining 3 SQL queries into one simple query
I have a strange 'problem' with one of my created queries. Given the next
I'm trying to migrate django apps, and i have problem with one. When i
I have one problem with parsing *.docx document with OpenXML (C#). So, here's my
I have one problem with Javascript Nodes.I want to find out what button was
i have one problem with handling list,i have three class named as UserInf,userData,userProcess,i created
I have one problem , I want to get some data from XML file

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.