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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:59:03+00:00 2026-06-01T18:59:03+00:00

Relations: Product( maker, model, type ) PC( model, speed, ram, hd, price) Laptop( model,

  • 0

Relations:

Product( maker, model, type )
PC( model, speed, ram, hd, price)
Laptop( model, speed, ram, hd, screen, price)
Printer( model, color, type, price)

I am currently trying to teach myself MySQL for work. I bought a book and am going through some example problems. I have come to a halt trying to figure out how I might structure these queries.

  1. Find, for each different speed, the average price of a PC
  2. Find, for each manufacturer, the average screen size of its laptops
  3. Find the manufacturers that make at least three different models of pc
  4. Find, for each manufacturer who sells pc’s, the maximum price of a pc
  5. Find, for each speed of pc above 2.0, the average price

I can do the average of a column easily ” SELECT AVG(price) FROM pc ” but I am not sure how to do the for each x find its average of y. Problems 1,2,4,5 are are structured like this, problem 3 I think would have a subquery within it as such, that I think will find a relation with the model, maker of each pc in it. But I am not sure how to do the second part “maker makes at least three different models”

(SELECT model, maker FROM product NATURAL JOIN pc WHERE type = 'pc')

Any help? Thanks in advance!

  • 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-01T18:59:04+00:00Added an answer on June 1, 2026 at 6:59 pm

    1/ The for X is done by using a GROUP BY:

    `SELECT speed, AVG(price) FROM PC GROUP BY speed`
    

    2/ is quite similar.. can you find it, after having read the GROUP BY Mysql Documentation?

    SELECT maker, AVG(speed) 
    FROM product p 
    JOIN laptop l 
    ON p.type="Laptop" AND p.model = l.model
    GROUP BY maker
    

    Logic: Same is 1, but here we need the maker. So we need to add the columns from Product. We join product with laptop, and then we group by maker.

    3/ is also group by, and you’ll want to use HAVING. Try it, ask in comments if you need more help or a solution.

    SELECT maker, COUNT(*)  
    FROM Product p 
    JOIN PC  
    ON p.type="OC" AND p.model = pc.model
    GROUP BY maker
    HAVING COUNT(*) > 3
    

    Same as 2: join product with PC, now group by maker, now only keep the rows which have a count higher than three. You can indeed do this with a subquery too:

    `SELECT maker 
    from product p 
    where (
      select COUNT(*) 
      from PC 
      where p.type="PC" and p.model = PC.model) 
    > 3`
    

    4/ will be a group by, and a join with product to get the maker

    Care to try this one again? Your first proposed solution is:

    SELECT maker, MAX(DISTINCT price) AS MaxPrice 
    FROM (
      SELECT model, maker, price 
      FROM product 
      NATURAL JOIN pc 
      WHERE type = 'pc') AS t5 
    GROUP BY maker
    
    • You don’t need a DISTINCT in the MAX, a max is always THE maximum,
      even if two rows have the same highest value. The GROUP BY is a kind
      of distinct, too.
    • Your subquery here is not really needed, and if you decide to
      subquery, think about which columns you need (do you need model?
      Why?).
    • Care to try the same logic as in 3, with a join?

    5/ is like 1, but with a WHERE-clause. No biggie.

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

Sidebar

Related Questions

Relations: Product(maker, model, type) Laptop(Model, price, speed, ram, hd, screen) PC(model, price, speed, ram,
Relations: Product(maker, model, type) Laptop(Model, price, speed, ram, hd, screen) PC(model, price, speed, ram,
Relations: Product(maker, model, type) Laptop(Model, price, speed, ram, hd, screen) PC(model, price, speed, ram,
Relations: Product(maker, model, type) Laptop(Model, price, speed, ram, hd, screen) PC(model, price, speed, ram,
I have this 3 tables in my DB: product (id, sku, type, price) ,
My user model has three relations for the same message model, and is using
I have two relations in my schema, product with many subcategory and product with
The project currently I'm working has the following code in the view: <%= product.provider.name
I am trying to update an whole entity object with relations in database in
I have a cart table which has a relation to a product table that

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.