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 DATABASE best_store; | |
CREATE TABLE "customer" ( | |
id SERIAL PRIMARY KEY, | |
name VARCHAR(150) NOT NULL, | |
email VARCHAR(100) NOT NULL UNIQUE, | |
password VARCHAR (50) NOT NULL | |
); | |
CREATE TABLE "customer_address" ( |
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 01: a quantidade de experiencias (experiences) atuais, ou seja, com “endDate” diferente de NULL -> As funções agregadas, tais como SUM, COUNT, AVG, MAX e MIN excluem os valores NULL, portanto: | |
SELECT COUNT("endDate") AS "currentExperiences" FROM experiences; | |
--Questão 02: a quantidade de graduações (educations) por usuário, incluindo o seu id: | |
SELECT "userId" AS id, COUNT(e."userId") AS educations FROM educations e GROUP BY "userId"; | |
-- Questão 03: a quantidade de depoimentos (testimonials) que o usuário com id 435 efetuou, incluindo o seu nome: | |
SELECT u.name AS writer, COUNT(t."writerId") AS "testimonialCount" | |
FROM testimonials t | |
JOIN users u ON t."writerId" = 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
-- Questão 01: todos os usuários (users) que vivem na cidade (cities) cujo nome seja “Rio de Janeiro”, ordenados pelo id do usuário: | |
SELECT u.id, u.name, c.name AS "city" | |
FROM users u | |
JOIN cities c ON u."cityId" = c.id | |
WHERE c.name = 'Rio de Janeiro' | |
ORDER By id; | |
-- Questão 02: todos os depoimentos (testimonials) cadastrados, incluindo o nome do remetente e do destinatário, ordenados pelo id do testiomial: | |
SELECT t.id, u1.name AS "writer", u2.name AS recipient, t.message |