We are now doing embedded mysql queries for a small local website. I am wondering how I might do this query “Ask the user for a price and find the PC whose price is closest to the desired price. Print the maker, model number, and speed of the PC.”
How might I find the pc with the price closest to the entered price from the user?
I know I need to do a natural join between product and pc, something along these lines
SELECT maker, model, speed FROM
(SELECT * FROM product NATURAL JOIN pc) AS t1
WHERE price (is close to) '$p';
Relations:
product(maker, model, type(pc, printer, laptop))
pc(model, price, speed, ram, hd size)
Create an offset variable by taking the price and subtracting the inputed price. Make this an absolute (no negatives) then order by this and limit