пятница, 7 марта 2014 г.

Задание: 25

Текст задания:
Найдите производителей принтеров, которые производят ПК с наименьшим объемом RAM и с самым быстрым процессором среди всех ПК, имеющих наименьший объем RAM.
Вывести: Maker.
Решение:

SELECT DISTINCT maker
FROM product
WHERE model IN (
SELECT model
FROM pc
WHERE ram = (
  SELECT MIN(ram)
  FROM pc
  )
AND speed = (
  SELECT MAX(speed)
  FROM pc
  WHERE ram = (
   SELECT MIN(ram)
   FROM pc
   )
  )
)
AND
maker IN (
SELECT maker
FROM product
WHERE type='printer'
);
Анализ плана выполнения запроса:
Стоимость: 0.03169197961688.
Количество операций: 16.

5 комментариев:

  1. SELECT DISTINCT maker
    FROM product
    WHERE maker IN (
    SELECT p.maker
    FROM product as p INNER JOIN pc as pc ON p.model=pc.model
    WHERE ram =(
    SELECT MIN(ram)
    FROM pc
    ) AND
    pc.speed=(
    SELECT MAX(speed)
    FROM pc
    WHERE speed IN (
    SELECT speed
    FROM pc
    WHERE ram=(
    SELECT MIN(ram) FROM pc))))
    AND type='printer'

    ОтветитьУдалить
  2. with data as (Select maker, ram, speed from product
    join pc on pc.model=product.model
    where type='PC' and maker in
    (select maker from product where type='Printer')and ram=(select min(ram) from pc))
    select distinct maker from data
    where speed=(select max(speed) from data)

    cost 0.039824958890676
    operations 20

    ОтветитьУдалить
  3. select distinct maker
    from product
    where maker in (
    select maker
    from product
    where model in (
    select model
    from PC
    where ram in (
    select min(ram)
    from PC)
    and speed in (
    select max(speed)
    from PC
    where ram in (
    select min(ram)
    from PC
    )
    )
    )
    )
    and type='Printer';

    ОтветитьУдалить
    Ответы
    1. прошу прощения, продублировал решение @callian91

      Удалить
  4. SELECT DISTINCT Product.maker
    FROM PC
    JOIN Product
    ON Product.model = PC.model
    WHERE maker IN (SELECT maker
    FROM Product
    WHERE type = 'PC' AND maker IN (SELECT maker
    FROM Product
    WHERE type = 'Printer'))
    AND PC.RAM <= (SELECT MIN (PC.RAM)
    FROM PC)
    AND PC.speed = (SELECT MAX(speed)
    FROM PC
    WHERE RAM <= (SELECT MIN (PC.RAM)
    FROM PC))

    ОтветитьУдалить