This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://dbdesigner.page.link/QPvDgas4e4A3tRGR6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE states ( | |
id SERIAL PRIMARY KEY, | |
name text NOT NULL | |
); | |
CREATE TABLE cities ( | |
id SERIAL PRIMARY KEY, | |
name text NOT NULL, | |
"stateId" INTEGER NOT NULL REFERENCES states(id) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Questão 1: | |
Select COUNT("endDate") AS "currentExperiences" FROM experiences; | |
-- Questão 2: | |
Select "userId" AS id, COUNT("userId") as educations from educations group by "userId"; | |
-- Questão 3: | |
Select u.name AS writer, COUNT(t."writerId") as "testimonialCount" from users u JOIN testimonials t ON | |
u.id = t."writerId" WHERE "writerId" = 435 GROUP BY u.id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 1 - Utilizando uma query, obtenha todos os usuários (users) que vivem na cidade (cities) cujo nome seja “Rio de Janeiro”. | |
SELECT users.id, users.name, cities.name as city FROM users JOIN cities ON users."cityId" = cities.id WHERE cities.name = 'Rio de Janeiro'; | |
-- 2 - Utilizando uma query, obtenha todos os depoimentos (testimonials) cadastrados, incluindo o nome do remetente e do destinatário. | |
SELECT testimonials.id, t1.name AS writer, t2.name AS recipient, testimonials.message FROM ((testimonials | |
JOIN users t1 ON testimonials."writerId" = t1.id) | |
JOIN users t2 ON testimonials."recipientId" = t2.id); | |
-- 3 - Utilizando uma query, obtenha todos os cursos (courses) que o usuário com id 30 já finalizou, incluindo o nome da escola. | |
-- O que indica que um usuário terminou um curso é o campo status da tabela educations, que deve estar como "finished". |