You are on page 1of 5

 3 industries revolution

o Agricultural
o Industrial
o Digital
 Now digital revolution
 Digital transformation – ex: uber

Ex:

select name, deathdate-birthdate


from people
where deathdate is not null and birthdate is not null
order by deathdate-birthdate desc
limit 3;

ex: when was the most profitable film released ??

select title,release_year, gross-budget as profit


from films
where gross is not null and budget is not null
order by profit desc
limit 5;

class 3:
BETWEEN
select title, release_year
from films
 where release_year between 1960 and 1969
 where release_year >= 1960 and release_year <1970

NOT EQUAL
select title, certification
from films
 where certification != 'R';
 not in ('R')
 don’t use like when you don’t have an exact value
AND
1 1 T
0 1 F
1 0 F
0 0 F
OR
1 1 T
0 1 T
1 0 T
0 0 F

T OR T AND F
T AND F
F

T OR (T AND F)
T OR F
T

--How many american movies are at least 2 hours long ?


select count(*) from films where duration >= 120 and country = 'USA'

--Film_id that have <1000 facebook_likes and user or number critics >500
select film_id
from reviews
where facebook_likes<1000 and (num_user>500 or num_critic>500);

% _

select distinct country


from films
where country like '__';

select distinct country


from films
where country like 'U_%';
 ALL THAT STARTS WITH U AND FROM 0 TO EVERYTHING
Lowercase
select country, lower(country)
from films
where lower(country) in ('usa', 'germamy');

find a film with specific words Alexander Horrible Bad Day

select title
from films
where title like '%Alexander%'
and title like '%Horrible%'
and title like '%Bad Day%';

-- how many people have the first name John?


select name
from people
where name like 'John %' ** space to don’t have Johnny
order by name desc

-- all firlms with 'the' in the title ?


select title
from films
where lower(title) like '% the %' or lower(title) like '%the %';

big thing in the exam:

count sum avg stddev variance min max

select count(distinct language), min(gross) , min(budget)


from films

--how many rows have non-null values in the gross column?


select count(*)
from films
where gross is not null ;

Group by

-- how many different languages did each country film?


select language, count(*)
from films
group by language
order by count(*)desc;

ex:

select country, language, count(*), min (gross)


from films
group by 1, 2
order by 1 asc;

ex2:
select release_year, count(distinct title)
from films
group by release_year
order by count(title) desc;

select * from
(select title, row_number() over (partition by title order by country)as fila from films) a
where a.fila>1;

select * from films where title = 'A Nightmare on Elm Street'

class 4

Join

select *
from films JOIN reviews
on films.id = reviews.film_id;

select title, release_year, imdb_score


from films f JOIN reviews r
on f.id = r.film_id;

query for
select title, release_year, country, imdb_score
from films as f JOIN reviews as r
on f.id = r.film_id
where f. release_year=2012
and r.imdb_score>7.5
select f.country, count(f.title), max(r.imdb_score), min(r.imdb_score), avg(r.imdb_score)
from films as f JOIN reviews as r
on f.id = r.film_id
where f.release_year> 2010
Group by f.country
order by 2 desc;

check final
select f.title,f.id,r.film_id, r.role, r.person_id, p.id, p.name
from films as f
join roles r on f.id=r.film_id
join people p on p.id = r.person_id
order by f.id, p.id

--which director created the most R rate movies?


select p.name, count(*) as film_count
from films as f
join roles r on f.id=r.film_id
join people p on p.id = r.person_id
where certification = 'R'
and r.role='director'
group by p.name
order by film_count desc;

OUTER JOIN

SLIDE 25

select c. code, c.name, l.name


from countries c
inner join languages l on c.code = l.code
order by c.code, l.name;

You might also like