MySQl最便宜的彩色打印机

时间:2012-04-05 16:00:00

标签: mysql

关系:

  • 产品(制造商,型号,型号)
  • 笔记本电脑(型号,价格,速度,内存,高清,屏幕)
  • PC(型号,价格,速度,内存,高清)
  • 打印机(型号,价格,颜色,价格)

我现在正试图找到最便宜的彩色打印机的制造商

我的查询:

SELECT maker FROM 
(SELECT model FROM printer NATURAL JOIN product WHERE printer.color = '1') AS t1  
WHERE price < all;

10 个答案:

答案 0 :(得分:2)

我这样解决了:

select distinct Pro.maker, Pri.price
from Product Pro join Printer Pri on Pro.model = Pri.model
where Pri.price = (select min(price) from Printer where color = 'y')  and Pri.color = 'y'

在子查询(select min(price) from Printer where color = 'y')中,我们应该指定只搜索彩色打印机的价格。

我在此解决方案中不喜欢的是我们必须对彩色打印机进行两次过滤:

    子查询(select min(price) from Printer where color = 'y') 中的
  • 在热门查询... and Pri.color = 'y'

虽然我不知道如何摆脱两地的指定。

答案 1 :(得分:1)

    SELECT `p.maker`
      FROM `product` AS `p`
INNER JOIN printer as pr
     WHERE p.model = pr.model
  ORDER BY pr.price ASC LIMIT 1

答案 2 :(得分:1)

使用子查询,你应该这样解决:

select pro.maker from printer pri
natural join product pro
where pri.color = '1'
  and pri.price <= all (select price from printer where pri.color = '1')

使用LIMIT子句:

select pro.maker from printer pri
natural join product pro
where pri.color = '1'
order by pri.price
limit 1

答案 3 :(得分:0)

在Mysql中,以下查询也有效:

select b.maker, min(a.price) from printer a, product b 
where a.color = '1'
and a.model = b.model;

答案 4 :(得分:0)

select distinct product.maker, price 
from printer
join product
on ( product.model=printer.model)
where color='y' and
price = (select min(price) from printer where color='y')

答案 5 :(得分:0)

SELECT DISTINCT maker, price 
FROM Printer 
JOIN Product 
ON Product.model=Printer.model 
WHERE Printer.color=1 
AND Printer.price=
(SELECT MIN(price) 
FROM Printer
WHERE color=1)

右。

您的查询结果:

maker      price

D          270.0000

答案 6 :(得分:0)

尝试以下查询:

Select distinct maker,price from Product 
Join Printer on printer.color='y'and Product.model= Printer.model
group by Printer.model
having price = (select min(price) from Printer where color='y')

答案 7 :(得分:0)

我是初学者,但我试过这个

select distinct p.maker, pr.price from

(select maker, model from product)p

inner join 

(select model, price from printer where color='y' and price=(select min(price) from 
printer where color='y'))pr

on p.model=pr.model

答案 8 :(得分:0)

select ‍product.maker, printer.price
from product join printer on product.model=printer.model
where price= (select min(price) from printer where color='y')

答案 9 :(得分:-1)

可以有多种解决方案,下面也有效。

哟可以试试这个,

select  top 1 t1.maker, t2.price from  product t1, printer t2
where t2.color = 'y'
and t1.model = t2.model order by t2.price