Giter Site home page Giter Site logo

12.4's Introduction

Домашнее задание к занятию 12.4. «SQL. Часть 2» - Мальцев Виктор


Задание 1

Одним запросом получите информацию о магазине, в котором обслуживается более 300 покупателей, и выведите в результат следующую информацию:

фамилия и имя сотрудника из этого магазина;
город нахождения магазина;
количество пользователей, закреплённых в этом магазине.

Ответ:

SELECT a.first_name, a.last_name, c.city, COUNT(c2.customer_id)
FROM sakila.staff a, sakila.store s, sakila.address a2, sakila.city c, sakila.customer c2
where a.store_id = s.store_id and s.address_id = a2.address_id and a2.city_id = c.city_id and a.store_id = c2.store_id group by a.staff_id having COUNT(c2.customer_id) > 300;

alt text


Задание 2

Получите количество фильмов, продолжительность которых больше средней продолжительности всех фильмов.

Ответ:

select COUNT(film_id) FROM sakila.film where length > (SELECT AVG(length) FROM sakila.film);

alt text


Задание 3

Получите информацию, за какой месяц была получена наибольшая сумма платежей, и добавьте информацию по количеству аренд за этот месяц.

Ответ:

select YEAR (payment_date), MONTH (payment_date), count(rental_id) from sakila.payment a group by YEAR (payment_date), MONTH (payment_date) order by sum(amount) DESC limit 1;

alt text

12.4's People

Contributors

vmmaltsev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.