D
D
dqwe932017-09-27 21:14:22
MySQL
dqwe93, 2017-09-27 21:14:22

Why is the request value not correct?

I am going through a task on a well-known site:
Source tables:
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, price, screen)
Printer(code, model, color, type, price)
Task itself:
Find the average price of PCs and PC notebooks produced by manufacturer A (Latin letter). Output: one total average price.
Here is my request

SELECT
SUM(Price)/SUM(Kol)
FROM
(SELECT
Price,
COUNT(PC.Code) as kol
FROM PC,Product
Where Pc.Model = Product.Model and Product.Maker = 'A'
GROUP BY PRICE
UNION ALL
SELECT
Price,
COUNT(Laptop.Code) as kol
FROM Laptop,Product
Where Laptop.Model = Product.Model and Product.Maker = 'A'
GROUP BY PRICE) as X

As a result, the result is a difference somewhere in 40K, I don’t understand where I have an error

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2017-09-27
@zontonax

And fuck such requests. I understand what an assignment is, but in a real project? What for? It is possible to calculate everything on the server.

R
Rsa97, 2017-09-27
@Rsa97

The error may be, for example, that there are laptops and laptops with the same name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question