0% found this document useful (0 votes)
5 views2 pages

SQL Queries for Auto Driver and Repair Data

The document contains a series of SQL queries related to auto drivers, auto repair, and auto streets. It includes selections, joins, unions, and groupings to retrieve and manipulate data from various tables. The queries focus on filtering, aggregating, and ordering data based on specific conditions and criteria.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

SQL Queries for Auto Driver and Repair Data

The document contains a series of SQL queries related to auto drivers, auto repair, and auto streets. It includes selections, joins, unions, and groupings to retrieve and manipulate data from various tables. The queries focus on filtering, aggregating, and ordering data based on specific conditions and criteria.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

a)

b) SELECT id, name, surname, id_auto FROM auto_drivers


c) SELECT id, name FROM auto_drivers
d) SELECT * FROM auto_drivers
e)
SELECT auto_drivers.name, auto_drivers.surname, auto_category.name AS category_auto,
auto_marka.name AS marka_auto
FROM auto_drivers
INNER JOIN auto_auto ON auto_auto.id = auto_drivers.id_auto
INNER JOIN auto_category ON auto_auto.id_category = auto_category.id
INNER JOIN auto_marka ON auto_marka.id = auto_auto.id_marka;
f) SELECT * FROM auto_repair ORDER BY price, date
g) SELECT * FROM auto_repair WHERE price > 400 AND price < 1800 ORDER BY
price
h) SELECT * FROM auto_repair WHERE price >= 600 OR id_problem = 1 ORDER BY
price
i)
SELECT @min_price := MIN(price) FROM auto_repair;
SELECT * FROM auto_repair WHERE price > @min_price
j) SELECT id, sale_buy, price, DATEDIFF(NOW(), auto_sale_buy.date) FROM
auto_sale_buy
k) SELECT id, sale_buy, price, DATEDIFF(NOW(), auto_sale_buy.date) AS time_tmp
FROM auto_sale_buy WHERE ((auto_sale_buy.sale_buy = 1) AND (price <= 3000))
OR (auto_sale_buy.sale_buy = 0) ORDER BY price
l) SELECT DISTINCT street_start FROM auto_street

БЛОК 2:
a) SELECT * FROM auto_drivers WHERE surname IS NULL
b) SELECT * FROM auto_drivers WHERE surname IS NOT NULL
c) SELECT * FROM `auto_drivers` WHERE name LIKE 'В%'
d)
SELECT surname FROM auto_drivers
UNION
SELECT name FROM auto_marka

БЛОК 3:
a) SELECT id, date, id_category, SUM(price) as total_price, AVG(price) as avg_price
FROM `auto_repair` GROUP BY id_category
b) SELECT * FROM `auto_repair` WHERE 1 GROUP BY id_personal
c) SELECT * FROM `auto_repair` WHERE 1 GROUP BY id_personal, id_category
d) SELECT id, date, id_personal, id_category, SUM(price) as total_price FROM
`auto_repair` GROUP BY id_category HAVING id_category <> 5
e) SELECT id, date, id_personal, id_category, SUM(price) as total_price FROM
`auto_repair` WHERE id_category <> 5 GROUP BY id_category
f) SELECT id, street_start, street_finish, intervall, COUNT(street_start) as count_street,
SUM(intervall) FROM `auto_street` GROUP BY street_start
БЛОК 4:
a) SELECT id, street_start, street_finish, intervall FROM `auto_street` WHERE intervall
IN(5, 10)
b) SELECT * FROM `auto_route` WHERE id_street = ANY(SELECT id FROM
`auto_street` WHERE auto_street.intervall = 10)
c) SELECT * FROM `auto_route` WHERE id_street = ALL(SELECT id FROM
`auto_street` WHERE auto_street.street_start <> 'Героїв майдану')
d) SELECT * FROM `auto_route` WHERE EXISTS(SELECT * FROM `auto_street`
WHERE auto_street.id = auto_route.id_street AND auto_street.street_start = 'Героїв
майдану' AND auto_street.intervall = 10)

You might also like