# Exercício 9 - Backend
1. Quais as categorias distintas e quantidade de personalidades em cada categoria são listadas?
```sql=
select
distinct t.category,
count(*)
from
times t
group by
t.category
```
2. Quantas honras foram dadas para nascidos entre 1920 e 1965 mas que não estejam entre o intervalo de nascidos entre 1945 a 1955? Dica: Utilize BETWEEN ;
```sql=
select
*
from
times t
where
t.birth_year between 1945 and 1955
```
3. Qual é a personalidade ainda viva hoje que possui data de nascimento listada mais antiga e não nula? Resposta sem subquery;
```sql=
select
t.year, t.honor ,t."name"
from
times t
where
t.death_year is null
and t.birth_year is not null
order by t.birth_year asc
limit 1
```
4. Assumindo a questão anterior, como você responderia essa questão utilizando subqueries? Dica: tente utilizar a subquery no WHERE .
```sql=
select
*
from
times t
where t.birth_year in (
select t2.birth_year from times t2 where t2.birth_year between 1945 and 1955
)
```
5. Quantos registros estão dentro das categorias: Revolution, Technology e Science? Não utilize o operador IN
```sql=
select
count(*)
from
times t
where
t.category ilike 'Revolution'
or t.category ilike 'Technology'
or t.category ilike 'Science'
```
6. A partir da questão 5, reescreva a consulta utilizando o operador IN
```sql=
select
count(*)
from
times
where
category in (
select
t.category
from
times t
where
t.category ilike 'Revolution'
or t.category ilike 'Technology'
or t.category ilike 'Science' )
```
7. [Responda em uma só consulta com subqueries] Para o ano de nascimento que teve a maior quantidade de celebridades como personalidade do ano, quem são as personalidades nascidas no mesmo? (Desconsidere a data nula com birth_year IS NOT NULL );
```sql=
select
"year" ,
honor ,
name
from
times
where
birth_year in (
select
birth_year
from
times
where
honor ilike '%person of the year%'
and birth_year is not null
group by birth_year
order by count(honor) desc
limit 1 )
```
8. Até 1998, a honra (honor) poderia ter vários nomes, Man of the Year, Woman of the Year e até mesmo Honor of the Year. Após essa data, o nome unificou-se e passou se chamar 'Person of the Year'.
i. Quais os nomes das honras dadas até 1998 (incluindo este ano).
```sql=
select
distinct honor
from
times
where
"year" between 1998 and 2020
```
ii. Com base na resposta anterior, quais honras foram destinadas puramente às mulheres
```sql=
select
distinct honor
from
times
where
year <= 1988
and honor ilike 'Woman%'
or honor ilike 'Women%'
```
e quantas foram destinadas a homens?
```sql=
select distinct
count(honor)
from
times
where
year <= 1988
and honor ilike 'man%'
or honor ilike 'men%'
```