--a) Selecionar todas as informações
--sobre todos os a utores (authors);
select * from authors
--b) Selecionar o código, primeiro nome e
-- último nome
--de todos os autores (authors) em
--ordem alfabética pelo último nome
--(au_lname);
select au_id, au_fname, au_lname
from authors
order by au_lname
--c) Selecionar todas as informações
--sobre todos os autores (authors)
--da cidade "Oakland";
select *
from authors
where city = 'Oakland'
--d) Selecionar o código, título e preço
--dos livros (titles) em ordem decrescente
--de preço;
select title_id, title, price
from titles
order by price desc
--e) Selecionar o código, título e preço
--dos livros (titles) cujo preço é
--superior a $15;
select title_id, title, price
from titles
where price > 15
--f) Selecionar o código e título dos
--livros (titles), primeiro e último
--nome dos seus respectivos autores
--(authors);
select t.title_id, t.title,
a.au_fname, a.au_lname
from titles as t
inner join titleauthor as ta
on (t.title_id = ta.title_id)
inner join authors as a
on (ta.au_id = a.au_id)
order by t.title_id, t.title
--g) Selecionar o código e título
--dos livros e quantidade de autores
--de cada livro (titles);
select t.title_id, t.title,
count (*) as qtd
from titles as t
inner join titleauthor as ta
on (t.title_id = ta.title_id)
inner join authors as a
on (ta.au_id = a.au_id)
group by t.title_id, t.title
--h) Selecionar o código e título dos
--livros (titles)que foram escritos por
--mais de 2 autores;
select t.title_id, t.title,
count (*) as qtd
from titles as t
inner join titleauthor as ta
on (t.title_id = ta.title_id)
inner join authors as a
on (ta.au_id = a.au_id)
group by t.title_id, t.title
having count (*) > 2
select * from
(select t.title_id, t.title,
count (*) as qtd
from titles as t
inner join titleauthor as ta
on (t.title_id = ta.title_id)
inner join authors as a
on (ta.au_id = a.au_id)
group by t.title_id, t.title) as tabela
where qtd > 2
--i) Selecionar o primeiro nome (fname), inicial do nome
-- do meio (minit) e o último nome (lname) dos
-- empregados (employee);
select fname, minit, lname
from employee
--j) Selecionar o código e a descrição dos
--cargos (jobs);
select job_id, job_desc
from jobs