среда, 18 декабря 2013 г.

Решение задач с сайта sql-ex.ru 1-10

sql
Задание: 1
Найдите номер модели, скорость и размер жесткого диска для всех ПК стоимостью менее 500 дол. Вывести: model, speed и hd
001
Select model ,  speed, hd  From pc  Where price < 500
Задание: 2
Найдите производителей принтеров. Вывести: maker
001
Select maker  from  product where product.type = 'printer' group by maker
Задание: 3
Найдите номер модели, объем памяти и размеры экранов ПК-блокнотов, цена которых превышает 1000 дол.
001
select model , ram ,  screen from laptop where price < 1000
Задание: 4
Найдите все записи таблицы Printer для цветных принтеров.
001
select * from printer where color = 'y'
Задание: 5
Найдите номер модели, скорость и размер жесткого диска ПК, имеющих 12x или 24x CD и цену менее 600 дол.
001
Select model ,speed , hd  from pc where (cd = '12x' or cd = '24x') and price < 600
Задание: 6
Укажите производителя и скорость для тех ПК-блокнотов, которые имеют жесткий диск объемом не менее 10 Гбайт.
001
002
Select maker, speed  from Product inner join Laptop on Product.model = Laptop.model
where hd <<span style="font-size: 0.857142857rem; line-height: 1.714285714;">= 10
Задание: 7
Найдите номера моделей и цены всех продуктов (любого типа), выпущенных производителем B (латинская буква).
001
002
003
004
005
006
007
008
Select laptop.model , laptop.price  from laptop inner join product on laptop.model = product.model
where product.maker= 'B'
union
Select pc.model , pc.price from pc inner join product on pc.model = product.model
where product.maker= 'B'
union
Select printer.model , printer.price from printer inner join product on printer.model = product.model
where product.maker= 'B'
Задание: 8
Найдите производителя, выпускающего ПК, но не ПК-блокноты.
001
002
select maker from product where type='PC' and maker not in
( select maker from product where type = 'Laptop') group by maker
Задание: 9
Найдите производителей ПК с процессором не менее 450 Мгц. Вывести: Maker
001
002
Select maker  from pc inner join product on pc.model = product.model where speed <= 450
group by maker
Задание: 10
Найдите принтеры, имеющие самую высокую цену. Вывести: model, price
001
select model, price  from printer where price = (select max(price) from printer)