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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:09:33+00:00 2026-06-13T18:09:33+00:00

Just a practice problem, little bit confusing I’d appreciate it if somebody could clear

  • 0

Just a practice problem, little bit confusing I’d appreciate it if somebody could clear this up..

I have a DB called Product and another one called PC. I’m trying to execute a query to “find the average hard disk size of a PC for all those manufacturers who also make printers”

Here’s my code:

SELECT maker, AVG(hd) 
FROM pc, product
WHERE pc.model=product.model
GROUP BY maker
HAVING COUNT(type='PR')>=1

type is an attribute of Product which either stands for printer(PR) laptop or PC, however the HAVING statement doesn’t seem to single out only the makers who produce printers, instead I get back an AVG for each maker in the Product table.

UPDATE

This is what the relations look like:

Product(maker, model, type)
PC(model, hd, speed, ram, price)
Printer(model, color, type, price)
  • 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-13T18:09:35+00:00Added an answer on June 13, 2026 at 6:09 pm

    Try the following query:

    SELECT maker, AVG(hd) FROM PC, Product
    WHERE PC.model=Product.model
    AND Product.maker IN 
       (SELECT DISTINCT maker FROM Product WHERE type='PR')
    GROUP BY Product.maker;
    

    Demo: http://sqlfiddle.com/#!2/abfaa/2

    You simply add a condition to make sure that the maker is one of the makers that have at least one printer product. You then group by the maker to find the individual averages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering about some practice about this; I have made a simple visual C#
I've just started to practice with PHP built-in gettype() and its return value. This
Just curious what is the best practice for solving the following issue. I have
Just to give a little more context to the question, I have a web
I've got a little problem with an exercise I have to finish. We have
My aim before writing this code was to just practice and learn more about
I've been trying to self-teach myself how to code but this practice problem is
I am studying for the AP CS Exam, and came across this practice problem
Right now I'm trying to create my own tiny MVC (just for practice and
I'm trying to create a Windows Form application in C#, mostly just to practice

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.