Created
April 4, 2018 18:16
-
-
Save AntonBikineev/0fec4ef05d61348f25eee8e778898da7 to your computer and use it in GitHub Desktop.
sql_tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT Клиент.ФИО, SUM(ТоварыЗаказа.Цена) | |
FROM Клиент | |
INNER JOIN Заказ ON Клиент.КлиентID = Заказ.КлиентID | |
INNER JOIN ТоварыЗаказа ON ТоварыЗаказа.ЗаказID = Заказ.ЗаказID | |
WHERE Заказ.Дата >= '2013-12-01' AND | |
Заказ.Дата <= '2013-12-31' | |
GROUP BY Клиент.КлиентID | |
HAVING SUM(ТоварыЗаказа.Цена) >= 10000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT A.адрес, A.дом, A.квартира | |
FROM A | |
INNER JOIN B ON (A.адрес LIKE '%телефон: ' || B.телефон || '%') AND | |
(B.телефон LIKE '+7495%890'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY (ФИО, ДатаРождения, Паспорт) ORDER BY ДатаЗанесения DESC) AS row | |
FROM Клиент) dups | |
WHERE dups.row > 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION date_diff(date, date) returns integer as $$ | |
SELECT $1 - $2; $$ language sql; | |
SELECT * | |
FROM (SELECT *, date_diff(date, min(Date_Visit) OVER (PARTITION BY Name ORDER BY Date_Visit)) AS since_first_day | |
FROM Посещения) people | |
WHERE people.since_first_day > 90; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment