{"id":24688916,"url":"https://github.com/guilhermenobrega/structured-query-language","last_synced_at":"2026-07-01T22:32:13.879Z","repository":{"id":273872453,"uuid":"921150153","full_name":"GuilhermeNobrega/Structured-Query-Language","owner":"GuilhermeNobrega","description":"SQL","archived":false,"fork":false,"pushed_at":"2025-07-30T14:57:15.000Z","size":49,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-31T00:40:40.713Z","etag":null,"topics":["declarative","declarative-language","sql","sql-ex-solutions","sql-exercises","sql-explain","sql-queries","sql-query"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GuilhermeNobrega.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-23T12:38:46.000Z","updated_at":"2025-08-06T21:25:05.000Z","dependencies_parsed_at":"2025-03-20T14:31:46.016Z","dependency_job_id":"55ab2b6b-95ae-4e3f-8b09-266a87846660","html_url":"https://github.com/GuilhermeNobrega/Structured-Query-Language","commit_stats":null,"previous_names":["guilhermenobrega/structured-query-language"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GuilhermeNobrega/Structured-Query-Language","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeNobrega%2FStructured-Query-Language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeNobrega%2FStructured-Query-Language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeNobrega%2FStructured-Query-Language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeNobrega%2FStructured-Query-Language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GuilhermeNobrega","download_url":"https://codeload.github.com/GuilhermeNobrega/Structured-Query-Language/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuilhermeNobrega%2FStructured-Query-Language/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35025980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-01T02:00:05.325Z","response_time":130,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["declarative","declarative-language","sql","sql-ex-solutions","sql-exercises","sql-explain","sql-queries","sql-query"],"created_at":"2025-01-26T17:19:18.975Z","updated_at":"2026-07-01T22:32:13.860Z","avatar_url":"https://github.com/GuilhermeNobrega.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL Exercises\n\n---\n\n## 🔹 Exercício 1 — JOIN + WHERE\n\n### **Enunciado:**\n\nListe o nome completo (`first_name` e `last_name`) e o item comprado por todos os clientes que **moram no Reino Unido (UK)** e compraram **algum produto com valor acima de 1000**.\n\n### **Resultado esperado:**\n- Campos: `first_name`, `last_name`, `item`\n- Filtro por país: `UK`\n- Filtro por valor: `amount \u003e 1000`\n\n### **Query:**\n\n```sql\nSELECT C.first_name, C.last_name, O.item\nFROM Customers C\nINNER JOIN Orders O ON C.customer_id = O.customer_id\nWHERE C.country = 'UK' AND O.amount \u003e 1000\nORDER BY C.customer_id ASC;\n```\n### ✔ Observações:\n- Use `=` ao invés de `IS` para comparar valores literais (`country = 'UK'`).\n- `IS` é usado geralmente para `NULL`, `TRUE`, `FALSE`.\n- A condição `O.amount \u003e 1000` é essencial para limitar aos pedidos de alto valor.\n\n---\n\n## 🔹 Exercício 2 — JOIN + GROUP BY + HAVING\n\n### **Enunciado:**\n\nMostre o `country` e o total de pedidos realizados por clientes de cada país, somente para países que realizaram mais de 1 pedido.\n\n### **Resultado esperado:**\n- Campos: `country`, `total_pedidos`\n- Filtro por países com mais de um pedido\n\n### **Query:**\n\n```sql\nSELECT C.country, COUNT(O.order_id) AS total_pedidos\nFROM Customers C\nINNER JOIN Orders O ON C.customer_id = O.customer_id\nGROUP BY C.country\nHAVING COUNT(O.order_id) \u003e 1\nORDER BY C.country;\n```\n### ✔ Observações:\n- GROUP BY agrupa os resultados por país.\n- HAVING é utilizado após o GROUP BY para filtrar os resultados agregados (diferente do WHERE que filtra linha a linha).\n- ORDER BY organiza o resultado final alfabeticamente pelo país.\n\n\n---\n\n\n## 🔹 Exercício 3 — Subquery + Filtro\n\n### **Enunciado:**\n\nListe o `first_name`, `last_name` e `country` de todos os clientes que **não fizeram nenhum pedido**.\n\n- Pode-se usar `SUBQUERY` ou `LEFT JOIN`.\n\n### **Resultado esperado:**\n- Campos: `first_name`, `last_name`, `country`\n- Somente clientes sem pedidos associados\n\n### **Query (com subquery):**\n\n```sql\nSELECT C.first_name as name, C.last_name as sobrenome, C.country as país\nFROM Customers C\nLEFT JOIN Orders O\nON C.customer_id = O.customer_id\nWHERE C.customer_id NOT IN(SELECT customer_id FROM Orders)\n\n--OU\n\nSELECT C.first_name AS name, C.last_name AS sobrenome, C.country AS país\nFROM Customers C\nLEFT JOIN Orders O ON C.customer_id = O.customer_id\nWHERE O.customer_id IS NULL;\n```\n---\n\n## 🔹 Exercício 4 — JOIN + GROUP BY + MAX\n\n### **Enunciado:**\n\nPara **cada país**, mostre o nome completo (`first_name` + `last_name`) do **cliente que fez o pedido de maior valor**.\n\n### **Resultado esperado:**\n- Campos: `country`, `first_name`, `last_name`, `amount`\n\n### **Query (versão simples com GROUP BY):**\n\n```sql\nSELECT C.country AS país, C.first_name AS name, C.last_name AS sobrenome, MAX(amount) as quantidade\nFROM Customers C\nLEFT JOIN Orders O \nON C.customer_id = O.customer_id\nGROUP BY C.country\n\n--OU\n\nSELECT C.country AS país, C.first_name AS name, C.last_name AS sobrenome, MAX(amount) as quantidade\nFROM Customers C\nLEFT JOIN Orders O \nON C.customer_id = O.customer_id\nGROUP BY C.country\nHAVING O.customer_id IS NOT NULL;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguilhermenobrega%2Fstructured-query-language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguilhermenobrega%2Fstructured-query-language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguilhermenobrega%2Fstructured-query-language/lists"}