Лабораторная работа: Новые операторы языка манипулирования данными (DML)
insert into Cosmetics
values(200,'Garnier Light','Day cream',1900,120,'3/8/2011','Avon','Nurzhanova Asel')
insert into Cosmetics
values(201,'MaxFactor','Eyelash',2300,209,'7/8/2010','Oriflame','Smailova Saya')
insert into Cosmetics
values(202,'Pharma','Makeupremover',3000,260,'11/18/2010','Maybeeline','Tanabaeva Gulzada')
insert into Cosmetics
values(203,'Baby Body','Lotion',300,80,'9/20/2012','Nivea','Erimbetova Laura')
1) CTE - выражения для упрощения читаемости запросов
with first as
(
select *
from Parfums
where destination like 'for women'
)
select * from first
order by price;
2) Однократный вызов CTE
WITH
maxi AS (SELECT (max (amount))AS v FROM Cosmetics),
mini AS (SELECT (min (price))AS v FROM Cosmetics)
SELECT cosmetic_id, cosmetic_name, amount, price
FROM Cosmetics as co, mini, maxi
WHERE co.amount=maxi.v or co.price= mini.v;
3) Использование CTE для рекурсивного прохода по дереву
WITH alphavit AS(
SELECT ASCII('A') code, CHAR(ASCII('A')) letter
UNION ALL
SELECT code+1, CHAR(code+1) FROM alphavit