Архитектура Аудит Военная наука Иностранные языки Медицина Металлургия Метрология Образование Политология Производство Психология Стандартизация Технологии |
Найти объем продаж заданного товара ⇐ ПредыдущаяСтр 2 из 2
· за квартал SELECT COUNT(o.created) AS count FROM zf322_belich.products AS p LEFT JOIN zf322_belich.orders_to_products as otp ON otp.products = p.id LEFT JOIN zf322_belich.orders as o ON o.id = otp.orders WHERE p.id = 3 AND o.created BETWEEN '2016-01-01' AND '2016-04-30'
· за год SELECT COUNT(o.created) AS count FROM zf322_belich.products AS p LEFT JOIN zf322_belich.orders_to_products as otp ON otp.products = p.id LEFT JOIN zf322_belich.orders as o ON o.id = otp.orders WHERE p.id = 3 AND extract(year from o.created) = 2016
· за этот же период среднюю цену SELECT round(AVG(p.price), 2) AS average_price FROM zf322_belich.products AS p LEFT JOIN zf322_belich.orders_to_products as otp ON otp.products = p.id LEFT JOIN zf322_belich.orders as o ON o.id = otp.orders WHERE o.created BETWEEN '2016-01-01' AND '2016-04-30' · за этот же период самую дорогую SELECT MAX(p.price) AS max_price FROM zf322_belich.products AS p LEFT JOIN zf322_belich.orders_to_products as otp ON otp.products = p.id LEFT JOIN zf322_belich.orders as o ON o.id = otp.orders WHERE o.created BETWEEN '2016-01-01' AND '2016-04-30'
· за этот же период самую дешевую вещь SELECT MIN(p.price) AS min_price FROM zf322_belich.products AS p LEFT JOIN zf322_belich.orders_to_products as otp ON otp.products = p.id LEFT JOIN zf322_belich.orders as o ON o.id = otp.orders WHERE o.created BETWEEN '2016-01-01' AND '2016-04-30' 6.5. Найти товары, поставляемые заданным поставщиком (выбор поставщика), чья дата продажи находится в заданных пределах (ввод интервала) SELECT t.name as product_type, p.name as product_name, p.created as product_date, p.price as product_price, o.created as order_date FROM zf322_belich.products AS p JOIN zf322_belich.types as t ON t.id = p.types LEFT JOIN zf322_belich.orders_to_products as otp ON otp.products = p.id LEFT JOIN zf322_belich.orders as o ON otp.orders = o.id WHERE p.sources = 2 AND o.created BETWEEN '2016-01-01' AND '2016-04-30'
6.6. Найти все товары для заданного места выпуска (выбор места), чья стоимость находится в заданных пределах (ввод интервала) SELECT t.name as product_type, p.name as product_name, p.created as product_date, p.price as product_price FROM zf322_belich.products AS p JOIN zf322_belich.types as t ON t.id = p.types WHERE p.places = 4 AND p.price BETWEEN 3000 AND 4000
6.7. Найти долю антиквариата, проданного за определенный период (ввод периода) от общего времени продажи SELECT COUNT(p.id) * 100 / (SELECT COUNT(id) FROM zf322_belich.products) as percent FROM zf322_belich.products AS p LEFT JOIN zf322_belich.orders_to_products as otp ON otp.products = p.id LEFT JOIN zf322_belich.orders as o ON otp.orders = o.id WHERE o.created BETWEEN '2016-01-01' AND '2016-03-30'
Найти весь товар, проступивший от заданного поставщика, чья стоимость больше, чем средняя стоимость заданного товара (выбор наименования), поступившего из заданной страны (выбор страны) SELECT t.name as product_type, p.name as product_name, p.created as product_date, p.price as product_price FROM zf322_belich.products AS p JOIN zf322_belich.types as t ON t.id = p.types WHERE p.sources = 2 AND p.price > (SELECT AVG(price) as price FROM zf322_belich.products WHERE types = 2 AND places = 1)
Найти долю дешевого товара (чья стоимость меньше заданной, ввод стоимости), поступившего от заданного поставщика и в целом SELECT SUM(CASE WHEN p.price < 2000 AND p.sources = 2 then 1 else 0 end) * 100 / count(*)||'%' as source_percent, SUM(CASE WHEN p.price < 2000 THEN 1 else 0 end) * 100 / count(*)||'%' as total_percent FROM zf322_belich.products as p 6.10. Найти среднюю стоимость товара, проданного за определенный промежуток времени (ввод интервала) SELECT round(AVG(p.price), 2) as average_price FROM zf322_belich.products as p JOIN zf322_belich.orders_to_products as otp ON otp.products = p.id JOIN zf322_belich.orders as o ON otp.orders = o.id WHERE o.created BETWEEN '2016-01-01' AND '2016-04-30'
Найти весь товар, чья стоимость выше, чем средняя стоимость товара заданного производителя SELECT t.name as product_type, p.name as product_name, p.created as product_date, p.price as product_price FROM zf322_belich.products AS p JOIN zf322_belich.types as t ON t.id = p.types WHERE p.price > (SELECT AVG(price) as price FROM zf322_belich.products WHERE sources = 2) Популярное:
|
Последнее изменение этой страницы: 2017-03-08; Просмотров: 352; Нарушение авторского права страницы