-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathlab-sql-2.sql
More file actions
80 lines (57 loc) · 2.01 KB
/
lab-sql-2.sql
File metadata and controls
80 lines (57 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use sakila;
-- Select all the actors with the first name ‘Scarlett"
select * from sakila.actor
where first_name='Scarlett';
-- Select all the actors with the last name ‘Johansson’
select * from sakila.actor
where last_name='Johansson';
-- How many films (movies) are available for rent?
select count(inventory_id) from inventory;
-- How many films have been rented?
select count(rental_id) from rental;
-- What is the shortest and longest rental period?
-- shortest
select rental_duration as shortest_rental
from film
order by rental_duration asc
limit 1;
select min(rental_duration)
from film;
-- longest
select rental_duration
from film
order by rental_duration desc
limit 1;
select max(rental_duration)
from film;
-- What are the shortest and longest movie duration? Name the values max_duration and min_duration
select min(length) as 'min_duration'
from film;
select max(length) as 'max_duration'
from film;
-- What's the average movie duration?
select avg(length)
from film;
-- What's the average movie duration expressed in format (hours, minutes)?
select avg(length)
from film;
select sec_to_time(AVG(film.length)*60) AS avg_duration
FROM film;
-- esta função lê qualquer número como segundos e o transforma em formato de tempo, então, como nosso dado era em minutos,
#precisamos primeiro multiplicar por 60, pra transformar em segundos
select CONCAT(FLOOR(AVG(film.length)/60) AS avg_duration
from film;
-- aqui, a função floor() arredonda a divisão pra baixo 'h'
select ROUND(AVG(film.length)%60) as avg_duration
from film; -- e aqui, os minutos restantes podem ser arredondados pra qualquer lado
-- acho que ta faltando algo; ainda vou pesquisar melhor essas funções;
-- How many movies longer than 3 hours?
select count(length)
from film
where length > '180';
-- Get the name and email formatted. Example: Mary SMITH - mary.smith@sakilacustomer.org.
select concat(lower(first_name),' ',last_name, '-', email)
from customer;
-- What's the length of the longest film title?
select max(length(title))
from film;