Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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">
Expand All @@ -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">
Expand All @@ -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">
Expand All @@ -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');

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.

Copy link
Author

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

```

<p align="center">
Expand All @@ -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">
Expand All @@ -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">
Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could show this in a cleaner and more readable way

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

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