0

关系:

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

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

我的查询:

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

10 回答 10

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'

虽然我不知道如何摆脱在这两个地方指定这一点。

于 2013-06-04T11:57:33.000 回答
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
于 2012-04-05T16:09:57.507 回答
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
于 2012-04-05T16:03:15.380 回答
0

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

select b.maker, min(a.price) from printer a, product b 
where a.color = '1'
and a.model = b.model;
于 2012-04-05T16:16:49.127 回答
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')
于 2015-03-13T01:20:38.737 回答
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')
于 2014-01-09T13:09:03.457 回答
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
于 2014-02-19T07:57:45.037 回答
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
于 2016-11-10T18:59:53.380 回答
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')
于 2020-05-12T07:26:04.237 回答
-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
于 2015-12-30T07:16:39.387 回答