-
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
Adding solutions to challenge 1 #57
Open
DavidH29
wants to merge
1
commit into
ravnhq:main
Choose a base branch
from
DavidH29: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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,9 @@ Now it's your turn to write SQL querys to achieve the following results: | |
1. Count the total number of states in each country. | ||
|
||
``` | ||
Your query here | ||
select c.name, count(c.id) from countries c | ||
inner join states s on c.id = s.country_id | ||
group by c.id; | ||
``` | ||
|
||
<p align="center"> | ||
|
@@ -84,7 +86,7 @@ Your query here | |
2. How many employees do not have supervisores. | ||
|
||
``` | ||
Your query here | ||
select count(*) employees_without_bosses from employees e where supervisor_id is null; | ||
``` | ||
|
||
<p align="center"> | ||
|
@@ -94,7 +96,11 @@ Your query here | |
3. List the top five offices address with the most amount of employees, order the result by country and display a column with a counter. | ||
|
||
``` | ||
Your query here | ||
select c.name, o.address, count(e.office_id) from offices o | ||
inner join countries c on o.country_id = c.id | ||
inner join employees e on o.id = e.office_id | ||
group by o.id, c.name | ||
order by count(e.office_id) desc limit 5; | ||
``` | ||
|
||
<p align="center"> | ||
|
@@ -104,7 +110,9 @@ Your query here | |
4. Three supervisors with the most amount of employees they are in charge. | ||
|
||
``` | ||
Your query here | ||
select supervisor_id, count(*) from employees e | ||
where supervisor_id is not null | ||
group by supervisor_id order by count(*) desc limit 3; | ||
``` | ||
|
||
<p align="center"> | ||
|
@@ -114,7 +122,8 @@ Your query here | |
5. How many offices are in the state of Colorado (United States). | ||
|
||
``` | ||
Your query here | ||
select count(*) list_of_office from offices o | ||
where state_id = (select id from states s where name ilike 'colorado'); | ||
``` | ||
|
||
<p align="center"> | ||
|
@@ -124,7 +133,10 @@ Your query here | |
6. The name of the office with its number of employees ordered in a desc. | ||
|
||
``` | ||
Your query here | ||
select o.name, count(e.office_id) from offices o | ||
inner join employees e on o.id = e.office_id | ||
group by o.id | ||
order by count(e.office_id) desc; | ||
``` | ||
|
||
<p align="center"> | ||
|
@@ -134,7 +146,14 @@ Your query here | |
7. The office with more and less employees. | ||
|
||
``` | ||
Your query here | ||
(select o.address , count(e.office_id) from offices o | ||
inner join employees e on o.id = e.office_id | ||
group by o.id | ||
order by count(e.office_id) desc limit 1) | ||
union all (select o.address, count(e.office_id) from offices o | ||
inner join employees e on o.id = e.office_id | ||
group by o.id | ||
order by count(e.office_id) limit 1); | ||
``` | ||
|
||
<p align="center"> | ||
|
@@ -144,9 +163,16 @@ Your query here | |
8. Show the uuid of the employee, first_name and lastname combined, email, job_title, the name of the office they belong to, the name of the country, the name of the state and the name of the boss (boss_name) | ||
|
||
``` | ||
Your query here | ||
select e.uuid, concat(e.first_name, ' ' ,e.last_name) full_name, e.email, e.job_title, o.name company, c.name country, s.name state, m.first_name boss_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you could show this in a cleaner and more readable way
|
||
from employees e | ||
inner join offices o on e.office_id = o.id | ||
inner join countries c on o.country_id = c.id | ||
inner join states s on o.state_id = s.id | ||
inner join employees m on e.supervisor_id = m.id; | ||
``` | ||
|
||
<p align="center"> | ||
<img src="src/results/result8.png" alt="result_8"/> | ||
</p> | ||
|
||
Challenge 3 link: https://dbdiagram.io/d/EDR-Challenge-3-674a25dbe9daa85aca2d1246 |
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.
I think the only case when an ILIKE command should be used is when there's a pattern matching task to be done. Here I don't understand why a simple name = 'Colorado' wouldn't be enough.
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.
This is actually a mistake from my side, I was just trying things and I have never had uses ILIKE before, I was testing how it behaved and forgot to change it to the original name = 'Colorado', my apologies