-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adding solutions of the exercises - challenge 1 #48
Open
franc1sc0sv
wants to merge
2
commits into
ravnhq:main
Choose a base branch
from
franc1sc0sv:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: "3.9" | ||
services: | ||
postgres: | ||
image: postgres:latest | ||
container_name: nerdery-container | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password123 | ||
ports: | ||
- "5000:5432" | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
- ./src/dump.sql:/docker-entrypoint-initdb.d/dump.sql | ||
|
||
volumes: | ||
postgres_data: |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,73 @@ | ||
-- Your answers here: | ||
-- 1 | ||
|
||
SELECT | ||
c.name, COUNT(s.name) as "count" | ||
FROM states s | ||
INNER JOIN countries c ON s.country_id = c.id | ||
GROUP BY c.name; | ||
-- 2 | ||
|
||
SELECT COUNT(*) | ||
employees_without_bosses | ||
FROM employees | ||
WHERE supervisor_id IS NULL; | ||
-- 3 | ||
|
||
SELECT | ||
c.name, | ||
o.address, | ||
COUNT(e.uuid) AS "count" | ||
FROM employees e | ||
INNER JOIN offices o ON e.office_id = o.id | ||
INNER JOIN countries c ON o.country_id = c.id | ||
GROUP BY c.name, o.address | ||
ORDER BY "count" DESC | ||
LIMIT 5; | ||
-- 4 | ||
|
||
SELECT e.supervisor_id, COUNT(*) AS total_employees | ||
FROM employees e | ||
WHERE e.supervisor_id IS NOT NULL | ||
GROUP BY e.supervisor_id | ||
ORDER BY total_employees DESC | ||
LIMIT 3; | ||
-- 5 | ||
|
||
SELECT | ||
COUNT(*) AS list_of_office | ||
FROM offices o | ||
WHERE o.country_id = 1 AND o.state_id = 8; | ||
-- 6 | ||
|
||
SELECT | ||
o.name AS "name", | ||
COUNT(e.office_id) AS "count" | ||
FROM employees e | ||
INNER JOIN offices o ON e.office_id = o.id | ||
GROUP BY o.name | ||
ORDER BY "count" DESC; | ||
-- 7 | ||
|
||
WITH cte AS ( | ||
SELECT | ||
o.name AS "name", | ||
COUNT(e.office_id) AS "count", | ||
ROW_NUMBER() OVER (ORDER BY COUNT(e.office_id) DESC) AS rn_desc, | ||
ROW_NUMBER() OVER (ORDER BY COUNT(e.office_id) ASC) AS rn_asc | ||
FROM employees e | ||
INNER JOIN offices o ON e.office_id = o.id | ||
GROUP BY o.name | ||
); | ||
SELECT "name", "count" | ||
FROM cte | ||
WHERE rn_asc = 1 OR rn_desc = 1; | ||
-- 8 | ||
SELECT | ||
e.uuid, | ||
CONCAT(e.first_name, ' ', e.last_name) AS full_name, | ||
e.email, | ||
e.job_title, | ||
o.name AS office_name, | ||
co.name AS country_name, | ||
s.name AS state_name, | ||
supervisors.first_name boss_name | ||
FROM employees e | ||
INNER JOIN offices o ON e.office_id = o.id | ||
INNER JOIN states s ON o.state_id = s.id | ||
INNER JOIN countries co ON s.country_id = co.id; | ||
INNER JOIN employees supervisors ON e.supervisor_id = supervisors.id | ||
WHERE supervisors.first_name IS NOT NULL; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the query doesn't return the boss name of an employee