Автор работы: Пользователь скрыл имя, 01 Июля 2013 в 19:40, курсовая работа
Основная база данных «Бакалея». Сформировать несколько таблиц. Предусмотреть: ввод данных, редактирование, просмотр данных. Реализовать следующие типы запросов с использованием нескольких таблиц:
Для каждого вида бакалейных товаров указать сведения о нём (наименование, дату выпуска, поставщик, цена, вес и т.п.).
Для каждого вида бакалеи выдать список, отсортированный:
по дате выпуска,
по весу,
по стоимости.
Тексты запросов и примеры работы
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
ORDER BY "Дата выпуска"
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
ORDER BY "Вес"
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
ORDER BY "Цена"
Команда:
SELECT
type as "Вид",
AVG(price) as "Средняя стоимость"
FROM product
GROUP BY type
ORDER BY "Средняя стоимость" DESC
LIMIT 1
Команда:
SELECT
type as "Вид",
AVG(price) as "Средняя стоимость"
FROM product
GROUP BY type
ORDER BY "Средняя стоимость"
LIMIT 1
Команда:
SELECT
type as "Вид",
AVG(price) as "Средняя стоимость"
FROM product
GROUP BY type
Команда:
SELECT
AVG(price) as "Средняя стоимость"
FROM product
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
WHERE product.price > 20
Команда:
SELECT
name as "Поставщик",
(CAST((SELECT COUNT(*) FROM product WHERE provider_id = 22) AS REAL)/
CAST((SELECT COUNT(*) FROM product) AS REAL) * 100.0) AS "Процент товаров поставщика"
FROM provider
WHERE provider_id = 22
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
WHERE product.date = '04.05.2013'
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
WHERE
(product.weight BETWEEN 1 AND 2) AND
(provider_id = 22)
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
WHERE
product.weight BETWEEN 1 AND 2
Команда:
SELECT
(CAST((SELECT COUNT(*) FROM product WHERE price BETWEEN 30 AND 60) AS REAL)/
CAST((SELECT COUNT(*) FROM product) AS REAL) * 100.0) AS "Процент товаров"
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
WHERE
(product.price > 20) AND
(provider_id = 22)
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
WHERE
provider_id = 22
Команда:
SELECT
(CAST((SELECT COUNT(*) FROM sales WHERE date BETWEEN '20.05.2013' AND '31.05.2013') AS REAL)/
CAST((SELECT COUNT(*) FROM sales) AS REAL) * 100.0) AS "Процент товаров"
Команда:
SELECT
name as "Поставщик",
(CAST((SELECT COUNT(*) FROM product WHERE (provider_id = 22) AND (price < 40)) AS REAL)/
CAST((SELECT COUNT(*) FROM product) AS REAL) * 100.0) AS "Процент товаров поставщика"
FROM provider
WHERE provider_id = 22
Команда:
SELECT
(CAST((SELECT COUNT(*) FROM product WHERE price < 40) AS REAL)/
CAST((SELECT COUNT(*) FROM product) AS REAL) * 100.0) AS "Процент товаров"
Команда:
SELECT AVG(product.price) AS "Средняя стоимость"
FROM product
INNER JOIN sales USING (product_id)
WHERE sales.date BETWEEN '20.05.2013' and '31.05.2013'
Команда:
SELECT
product.type as "Вид",
product.name as "Наименование",
product.date as "Дата выпуска",
provider.name as "Поставщик",
product.price as "Цена",
product.weight as "Вес"
FROM product
INNER JOIN provider USING (provider_id)
WHERE product.price > (SELECT AVG(price) FROM product WHERE provider_id = 15)
Анализ результатов и выводы
В результате проделанной работы мы изучили базовые операции по работе с базой данных; изучили синтаксис команд; приобрели навыки создания, заполнения и модификации таблиц базы данных, работы с транзакциями в PostgreSQL, приобрели навыки создания запросов в PostgreSQL.
Список использованной литературы