├── 01-projectList ├── README.md └── projectList.sql ├── 02-countriesSelection ├── README.md └── countriesSelection.sql ├── 03-monthlyScholarships ├── README.md └── monthlyScholarships.sql ├── 04-projectsTeam ├── README.md └── projectsTeam.sql ├── 05-automaticNotifications ├── README.md └── automaticNotifications.sql ├── 06-volleyballResults ├── README.md └── volleyballResults.sql ├── 07-mostExpensive ├── README.md └── mostExpensive.sql ├── 08-contestLeaderboard ├── README.md └── contestLeaderboard.sql ├── 09-gradeDistribution ├── README.md └── gradeDistribution.sql ├── 10-mischievousNephews ├── README.md └── mischievousNephews.sql ├── 11-suspectsInvestigation ├── README.md └── suspectsInvestigation.sql ├── 12-suspectsInvestigation2 ├── README.md └── suspectsInvestigation2.sql ├── 13-securityBreach ├── README.md └── securityBreach.sql ├── 14-testCheck ├── README.md └── testCheck.sql ├── 15-expressionsVerification ├── README.md └── expressionsVerification.sql ├── 16-newsSubscribers ├── README.md └── newsSubscribers.sql ├── 17-countriesInfo ├── README.md └── countriesInfo.sql ├── 18-itemCounts ├── README.md └── itemCounts.sql ├── 19-usersByContinent ├── README.md └── usersByContinent.sql ├── 20-movieDirectors ├── README.md └── movieDirectors.sql ├── 21-travelDiary ├── README.md └── travelDiary.sql ├── 22-soccerPlayers ├── README.md └── soccerPlayers.sql ├── 23-marketReport ├── README.md └── marketReport.sql ├── 24-websiteHacking ├── README.md └── websiteHacking.sql ├── 25-nullIntern ├── README.md └── nullIntern.sql ├── 26-legsCount ├── README.md └── legsCount.sql ├── 27-combinationLock ├── README.md └── combinationLock.sql ├── 28-interestClub ├── README.md └── interestClub.sql ├── 29-personalHobbies ├── README.md └── personalHobbies.sql ├── 30-booksCatalogs ├── README.md └── booksCatalogs.sql ├── 31-habitatArea ├── README.md └── habitatArea.sql ├── 32-orderOfSuccession ├── README.md └── orderOfSuccession.sql ├── 33-orderingEmails ├── README.md └── orderingEmails.sql ├── 34-placesOfInterest ├── README.md └── placesOfInterest.sql ├── 35-soccerGameSeries ├── README.md └── soccerGameSeries.sql ├── 36-correctIPs ├── README.md └── correctIPs.sql ├── 37-validPhoneNumbers ├── README.md └── validPhoneNumbers.sql ├── 38-importantEvents ├── README.md └── importantEvents.sql ├── 39-dateFormatting ├── README.md └── dateFormatting.sql ├── 40-pastEvents ├── README.md └── pastEvents.sql ├── 41-netIncome ├── README.md └── netIncome.sql ├── 42-alarmClocks ├── README.md └── alarmClocks.sql ├── 43-companyEmployees ├── README.md └── companyEmployees.sql ├── 44-scholarshipsDistribution ├── README.md └── scholarshipsDistribution.sql ├── 45-userCountries ├── README.md └── userCountries.sql ├── 46-placesOfInterestPairs ├── README.md └── placesOfInterestPairs.sql ├── 47-localCalendar ├── README.md └── localCalendar.sql ├── 48-routeLength ├── README.md └── routeLength.sql ├── 49-currencyCodes ├── README.md └── currencyCodes.sql ├── 50-coursesDistribution ├── README.md └── coursesDistribution.sql ├── 51-nicknames ├── README.md └── nicknames.sql ├── 52-tableSecurity ├── README.md └── tableSecurity.sql ├── 53-officeBranches ├── README.md └── officeBranches.sql ├── 54-restaurantInfo ├── README.md └── restaurantInfo.sql ├── 55-studentsInClubs ├── README.md └── studentsInClubs.sql ├── 56-emptyDepartments ├── README.md └── emptyDepartments.sql ├── 57-sunnyHolidays ├── README.md └── sunnyHolidays.sql ├── 58-closestCells ├── README.md └── closestCells.sql ├── 59-top5AverageGrade ├── README.md └── top5AverageGrade.sql ├── 60-salaryDifference ├── README.md └── salaryDifference.sql ├── 61-recentHires ├── README.md └── recentHires.sql ├── 62-checkExpenditure ├── README.md └── checkExpenditure.sql ├── 63-dancingCompetition ├── README.md └── dancingCompetition.sql ├── 64-trackingSystem ├── README.md └── trackingSystem.sql ├── 65-storageOptimization ├── README.md └── storageOptimization.sql ├── 66-consecutiveIds ├── README.md └── consecutiveIds.sql ├── 67-holidayEvent ├── README.md └── holidayEvent.sql ├── 68-hostnamesOrdering ├── README.md └── hostnamesOrdering.sql ├── 69-orderAnalytics ├── README.md └── orderAnalytics.sql ├── 70-customerMessages ├── README.md └── customerMessages.sql ├── 71-orderPrices ├── README.md └── orderPrices.sql ├── 72-findTable ├── README.md └── findTable.sql ├── 73-queriesExecution ├── README.md └── queriesExecution.sql ├── 74-filmLibrary ├── README.md └── filmLibrary.sql ├── 75-bugsInComponent ├── README.md └── bugsInComponent.sql ├── 76-freeSeats ├── README.md └── freeSeats.sql ├── 77-giftPackaging ├── README.md └── giftPackaging.sql ├── 78-stringsStatistics ├── README.md └── stringsStatistics.sql ├── 79-unluckyEmployees ├── README.md └── unluckyEmployees.sql ├── 80-driversInfo ├── README.md └── driversInfo.sql ├── 81-sortBookChapters ├── README.md └── sortBookChapters.sql ├── 82-typeInheritance ├── README.md └── typeInheritance.sql ├── 83-battleshipGameResults ├── README.md └── battleshipGameResults.sql └── 84-tictactoeTournament ├── README.md └── tictactoeTournament.sql /01-projectList/README.md: -------------------------------------------------------------------------------- 1 |

Project List

2 |

source: codesignal.com 3 |

Your boss wants to identify the successful projects running in your company, so he asked you to prepare a list of all the currently active projects and their average monthly income.

4 |

You have stored the information about these projects in a simple database with a single Projects table that has five columns:

5 | 12 |

Your boss says that internal project ids are irrelevant to him and that he isn't interested in how big the teams are. Since that's the case, he wants you to create another table by removing the internal_id and team_size columns from the existing Projects table. Return it sorted by internal_id in ascending order.

13 |

Example

14 |

For the following table Projects

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
internal_idproject_nameteam_sizeteam_leadincome
1384MapReduce100Jeffrey Dean0
2855Windows1000Bill Gates100500
5961Snapchat3Evan Spiegel2000
45 | the resulting table should be 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
project_nameteam_leadincome
MapReduceJeffrey Dean0
WindowsBill Gates100500
SnapchatEvan Spiegel2000
68 | 71 |
72 | -------------------------------------------------------------------------------- /01-projectList/projectList.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE projectList() 2 | BEGIN 3 | SELECT project_name, team_lead, income 4 | FROM Projects 5 | ORDER BY internal_id; 6 | END -------------------------------------------------------------------------------- /02-countriesSelection/README.md: -------------------------------------------------------------------------------- 1 |

Countries Selection

2 |

source: codesignal.com 3 |

Your friend wants to become a professional tour guide and travel all around the world. In pursuit of this dream, she enrolled in tour guide school. The professors in this school turned out to be very demanding, and one of them gave your friend a difficult assignment that she has to finish over the weekend.

4 |

Here's the assignment: Given a list of countries, your friend should identify all the countries that are in Africa. To help her, you have decided to write a function that will find all such countries from any set of countries. The countries table in which the countries are stored has the following structure:

5 | 10 |

Your task is to return a new table that has the same columns, but that only contains the countries from Africa. The countries should be sorted alphabetically by their names.

11 |

Example

12 |

For the following table countries

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
namecontinentpopulation
AustriaEurope8767919
BelizeNorth America375909
BotswanaAfrica2230905
CambodiaAsia15626444
CameroonAfrica22709892
45 |

the output should be

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
namecontinentpopulation
BotswanaAfrica2230905
CameroonAfrica22709892
63 | 66 |
67 | -------------------------------------------------------------------------------- /02-countriesSelection/countriesSelection.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE countriesSelection() 2 | BEGIN 3 | SELECT * FROM countries WHERE continent = 'Africa' ORDER by name; 4 | END -------------------------------------------------------------------------------- /03-monthlyScholarships/README.md: -------------------------------------------------------------------------------- 1 |

Monthly Scholarships

2 |

source: codesignal.com 3 |

Students at your university get scholarships that are paid out throughout the year.

4 |

Information about the scholarships is stored in the table scholarships, which has the structure:

5 | 9 |

Now you need to calculate the amount of money each student should get per month. Given the table scholarships, build the resulting table as follows: The table should have the same columns as the initial table, but the scholarship column should contain the amount of the student's monthly scholarship payout. The rows should be ordered by the students' ids.

10 |

Example

11 |

For the following table scholarships

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
idscholarship
112000
218000
324000
415000
521000
613000
42 |

the output should be

43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
idscholarship
11000
21500
32000
41250
51750
61083.3333333333333
73 | 76 |
77 | -------------------------------------------------------------------------------- /03-monthlyScholarships/monthlyScholarships.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE monthlyScholarships() 2 | BEGIN 3 | SELECT id, scholarship/12 as scholarship 4 | FROM scholarships; 5 | END -------------------------------------------------------------------------------- /04-projectsTeam/README.md: -------------------------------------------------------------------------------- 1 |

Projects Team

2 |

source: codesignal.com 3 |

You've been promoted and assigned to a new project. The problem is, you don't know who you are working with and your predecessor has vanished without a trace! Luckily, each project in your company keeps its own activity database, which you are going to use to find out the names of your new colleagues.

4 |

Information about the project's activity is stored in table projectLog, which has the following structure:

5 | 11 |

You only have access to the project's most recent history, but this should be enough for you. You've decided that finding everyone who interacted with the project in this period is the best way to start.

12 |

Given the table projectLog, build a new results table with a single name column that contains the names of the project's contributors sorted in ascending order.

13 |

Example

14 |

For the following table projectLog

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
idnamedescriptiontimestamp
1James Smithadd new logo2015-11-10 15:24:32
2John Johnsonupdate license2015-11-10 15:50:01
3John Johnsonfix typos2015-11-10 15:55:01
4James Smithupdate logo2015-11-10 17:53:04
5James Smithdelete old logo2015-11-10 17:54:04
6Michael Williamsfix the build2015-11-12 13:37:00
7Mary Troppinsadd new feature2015-11-08 17:54:04
8James Smithfix fonts2015-11-14 13:54:04
9Richard Youngremove unneeded files2015-11-14 00:00:00
10Michael Williamsadd tests2015-11-09 11:53:00
83 |

the output should be

84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
name
James Smith
John Johnson
Mary Troppins
Michael Williams
Richard Young
104 | 107 |
108 | -------------------------------------------------------------------------------- /04-projectsTeam/projectsTeam.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE projectsTeam() 2 | BEGIN 3 | SELECT DISTINCT(name) as name 4 | FROM projectLog 5 | ORDER BY name; 6 | END -------------------------------------------------------------------------------- /05-automaticNotifications/README.md: -------------------------------------------------------------------------------- 1 |

Automatic Notifications

2 |

source: codesignal.com 3 |

The application you've been working on for the past year is a huge success! It already has a large and active user community. You know the ID number, username, and email of each user. Each user also has a specific role that shows their position in the community. Information about the users is stored in the database as a table users, which has the following structure:

4 | 10 |

You want to send users automatic notifications to let them know about the most recent updates. However, not all users should get these notifications: Administrators don't need notifications since they know about the updates already, and premium users don't need them since they get personalized weekly updates.

11 |

Given the users table, your task is to return the emails of all the users who should get notifications, i.e. those whose role is not equal to "admin" or "premium". Note that roles are case insensitive, so users with roles of "Admin", "pReMiUm", etc. should also be excluded.

12 |

The resulting table should contain a single email column and be sorted by emails in ascending order.

13 |

Example

14 |

For the following table users

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
idusernameroleemail
6fasalytchpremiummuch.premium@role.com
13luckygirlregularfun@meh.com
16todayhumorgurutoday@humor.com
23Felixadminfelix@codesignal.com
52admin666AdmiNiamtheadmin@admin.admin
87solver100500regularemail@notbot.com
59 |

the resulting table should be

60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
email
email@notbot.com
fun@meh.com
today@humor.com
74 |

The only three users who should get notifications are luckygirl, todayhumor, and solver100500. Their emails are fun@meh.com, today@humor.com, and email@notbot.com respectively, which should be sorted as email@notbot.com, fun@meh.com, and today@humor.com.

75 | 78 |
79 | -------------------------------------------------------------------------------- /05-automaticNotifications/automaticNotifications.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE automaticNotifications() 2 | SELECT email 3 | FROM users 4 | WHERE role NOT IN ("admin", "premium") 5 | ORDER BY email; 6 | -------------------------------------------------------------------------------- /06-volleyballResults/README.md: -------------------------------------------------------------------------------- 1 |

Volleyball Results

2 |

source: codesignal.com 3 |

You are creating a website that will help you and your friends keep track of the results of volleyball teams from all around the world. Your website regularly crawls the web searching for new games, and adds the results of these games to the results table stored in your local database. After each update, the table should be sorted in ascending order by the total number of games won. This year's results are quite marvelous - at any given moment there are no two teams that have won the same number of games!

4 |

The results table contains the following columns:

5 | 12 |

Your task is to sort the given results table in ascending order by the number of wins.

13 |

Example

14 |

For given table results

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
namecountryscoredmissedwins
FC TokyoJapan26281
FujianChina24260
Jesus MariaArgentina25233
University BluesAustralia16252
52 |

the output should be

53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 |
namecountryscoredmissedwins
FujianChina24260
FC TokyoJapan26281
University BluesAustralia16252
Jesus MariaArgentina25233
90 | 93 |
94 | -------------------------------------------------------------------------------- /06-volleyballResults/volleyballResults.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE volleyballResults() 2 | BEGIN 3 | SELECT * FROM results 4 | ORDER BY wins ASC; 5 | END -------------------------------------------------------------------------------- /07-mostExpensive/README.md: -------------------------------------------------------------------------------- 1 |

Most Expensive

2 |

source: codesignal.com 3 |

Mr. Cash wants to keep track of his expenses, so he has prepared a list of all the products he bought this month. Now he is interested in finding the product on which he spent the largest amount of money. If there are products that cost the same amount of money, he'd like to find the one with the lexicographically smallest name.

4 |

The list of expenses is stored in a table Products which has the following columns:

5 | 11 |

The resulting table should contain one row with a single column: the product with the lexicographically smallest name on which Mr. Cash spent the largest amount of money.

12 |

The total amount of money spent on a product is calculated as price * quantity.

13 |

Example

14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
idnamepricequantity
1MacBook Air15001
2Magic Mouse791
3Spray cleaner103

the output should be

43 | 44 |
45 | 46 | 47 | 48 | 49 | 50 | 51 |
name
MacBook Air
52 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
idnamepricequantity
1Tomato104
2Cucumber85
3Red Pepper202
4Feta401

the output should be

87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 |
name
Cucumber
96 |

While the total cost for each product was 40, Cucumber has the lexicographically smallest name.

97 | 100 |
101 | -------------------------------------------------------------------------------- /07-mostExpensive/mostExpensive.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE mostExpensive() 2 | BEGIN 3 | SELECT name FROM Products 4 | ORDER BY price*quantity DESC, name 5 | LIMIT 1; 6 | END -------------------------------------------------------------------------------- /08-contestLeaderboard/README.md: -------------------------------------------------------------------------------- 1 |

Contest Leaderboard

2 |

source: codesignal.com 3 |

You are working as a recruiter at a big IT company, and you're actively looking for candidates who take the top places in major programming contests. Since the grand finale of the annual City Competition, you've been reaching out to the top participants from the leaderboard, and successfully so.

4 |

You have already interviewed all the prize winners (the top 3 participants), but that's not enough right now. Your company needs more specialists, so now you would like to connect with the participants who took the next 5 places.

5 |

The contest leaderboard is stored in a table leaderboard with the following columns:

6 | 11 |

The resulting table should contain the names of the participants who took the 4th to 8th places inclusive, sorted in descending order of their places. If there are fewer than 8 participants, the results should contain those who ranked lower than 3rd place.

12 |

It is guaranteed that there are at least 3 prize winners in the leaderboard and that all participants have different scores.

13 |

Example

14 |

For the following table leaderboard

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
idnamescore
1gongy3001
2urandom2401
3eduardische2477
4Gassa2999
5bcc322658
6Alex_2oo86000
7mirosuaf2479
8Sparik2399
9thomas_holmes2478
10cthaeghya2400
72 |

the output should be

73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
name
bcc32
mirosuaf
thomas_holmes
eduardische
urandom
93 | 96 |
97 | -------------------------------------------------------------------------------- /08-contestLeaderboard/contestLeaderboard.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE contestLeaderboard() 2 | BEGIN 3 | SELECT name FROM leaderboard 4 | ORDER By score DESC 5 | LIMIT 3,5; 6 | END -------------------------------------------------------------------------------- /09-gradeDistribution/README.md: -------------------------------------------------------------------------------- 1 |

Grade Distribution

2 |

source: codesignal.com 3 |

At the end of every semester your professor for "Introduction to Databases" saves the exam results of every student in a simple database system. In the database table Grades, there are five columns:

4 | 11 |

According to school policy, there are three possible ways to evaluate a grade:

12 | 32 |

Each student's final grade comes from the option that works the best for that student.

33 |

As a Teaching Assistant (TA), you need to query the name and id of all the students whose best grade comes from Option 3, sorted based on the first 3 characters of their name. If the first 3 characters of two names are the same, then the student with the lower ID value comes first.

34 |

Example

35 |

For the following table Grades

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
NameIDMidterm1Midterm2Final
David423343454124
Anthony545281001050
Jonathan587544958121
Jonty110002530180
73 |

Output should be

74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 |
NameID
David42334
Jonty11000
Jonathan58754
92 |

For David, Jonty and Jonathan, the best option is number 3. But Anthony's best option is the second one, because Option1 = 25% of 100 + 25% of 10 +50% of 50 = 52.5, Option2 = 50% of 100 + 50% of 10 = 55, Option3 = 100% of 50 = 50.

93 | 96 |
97 | -------------------------------------------------------------------------------- /09-gradeDistribution/gradeDistribution.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE gradeDistribution() 2 | BEGIN 3 | SELECT Name, ID FROM Grades 4 | WHERE Final > Midterm1*.25+Midterm2*.25+Final*.5 && Midterm1*.5+Midterm2*.5 5 | ORDER BY LEFT(Name, 3), ID ASC; 6 | END -------------------------------------------------------------------------------- /10-mischievousNephews/README.md: -------------------------------------------------------------------------------- 1 |

Mischievous Nephews

2 |

source: codesignal.com 3 |

Your nephews Huey, Dewey, and Louie are staying with you over the winter holidays. Ever since they arrived, you've hardly had a day go by without some kind of incident - the little rascals do whatever they please! Actually, you're not even mad; the ideas they come up with are pretty amazing, and it looks like there's even a system to their mischief.

4 |

You decided to track and analyze their behavior, so you created the mischief table in your local database. The table has the following columns:

5 | 10 |

It looks like each of your nephews is active on a specific day of the week. You decide to check your theory by creating another table as follows:
11 | The resulting table should contain four columns, weekday, mischief_date, author, and title, where weekday is the weekday of mischief_date (0 for Monday, 1 for Tuesday, and so on, with 6 for Sunday). The table should be sorted by the weekday column, and for each weekday Huey's mischief should go first, Dewey's should go next, and Louie's should go last. In case of a tie, mischief_date should be a tie-breaker. If there's still a tie, the record with the lexicographically smallest title should go first.

12 |

It is guaranteed that all entries of mischief are unique.

13 |

Example

14 |

For the following table mischief

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
mischief_dateauthortitle
2016-12-01DeweyCook the golden fish in a bucket
2016-12-01DeweyPaint the walls pink
2016-12-01HueyEat all the candies
2016-12-01LouieWrap the cat in toilet paper
2016-12-08LouiePlay hockey on linoleum
2017-01-01HueySmash a window
2017-02-06DeweyCreate a rink on the porch
57 |

the output should be

58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
weekdaymischief_dateauthortitle
02017-02-06DeweyCreate a rink on the porch
32016-12-01HueyEat all the candies
32016-12-01DeweyCook the golden fish in a bucket
32016-12-01DeweyPaint the walls pink
32016-12-01LouieWrap the cat in toilet paper
32016-12-08LouiePlay hockey on linoleum
62017-01-01HueySmash a window
108 |

The first and the eighth of December are Thursdays, the sixth of February is a Monday, and the first of January is a Sunday.

109 |

The dates in the example are given in the format YYYY-MM-DD.

110 | 113 |
114 | -------------------------------------------------------------------------------- /10-mischievousNephews/mischievousNephews.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE mischievousNephews() 2 | BEGIN 3 | SELECT WEEKDAY(mischief_date) as weekday, mischief_date, author, title 4 | FROM mischief 5 | ORDER BY weekday, FIELD(author,"Huey", "Dewey","Louie"), mischief_date, title; 6 | END -------------------------------------------------------------------------------- /11-suspectsInvestigation/README.md: -------------------------------------------------------------------------------- 1 |

Suspects Investigation

2 |

source: codesignal.com 3 |

A large amount of money was stolen today from the main city bank, and as the chief of police it's your duty to find the robber.

4 |

You store information about your suspects in the table Suspect, which has the structure:

5 | 12 |

You have already gathered some evidence and discovered the following clues:

13 | 17 |

To make the list of suspects smaller, you would like to filter out the suspects who can't possibly be guilty according to the information obtained from the clues. For each remaining suspect, you want to save his/her id, name and surname. Please note that the information obtained from the clue should be considered case-insensitive, so for example "bill Green", and "Bill green", and "Bill Green" should all be included in the new table.

18 |

Given the table Suspect, build the resulting table as follows: the table should have columns id, name and surname and its values should be ordered by the suspects' ids in ascending order.

19 |

Example

20 |

For the following table Suspect

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
idnamesurnameheightweight
1JohnDoe16560
2BillGreen17067
3BaelfireGrehn17270
4BillGretan16555
5BrendonGrewn15050
6billGreen16950
72 |

the output should be

73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
idnamesurname
2BillGreen
5BrendonGrewn
6billGreen
95 |

The name of the 1st suspect doesn't start with "B", the 3rd suspect is taller than 170cm, and the surname of the 4th suspect doesn't match the given pattern, meaning that these suspects are not included in the results.

96 | 99 |
100 | -------------------------------------------------------------------------------- /11-suspectsInvestigation/suspectsInvestigation.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE suspectsInvestigation() 2 | BEGIN 3 | SELECT id, name, surname 4 | FROM Suspect 5 | WHERE height <= 170 6 | AND name like 'B%' 7 | AND surname like 'Gre_n' 8 | ORDER BY id ASC; 9 | END -------------------------------------------------------------------------------- /12-suspectsInvestigation2/README.md: -------------------------------------------------------------------------------- 1 |

Suspects Investigation 2

2 |

source: codesignal.com 3 |

A large amount of money was stolen today from the main city bank, and as the chief of police it's your duty to find the robber.

4 |

You store information about your suspects in the table Suspect, which has the structure:

5 | 12 |

You have already gathered some evidence and discovered the following clues:

13 | 17 |

The clues you've obtained allow you to let some suspects go since they can't possibly be guilty, so now you need to build a list that contains the people who can be freed based on the gathered information. For each of these people, you need to know his/her id, name and surname. Please note that the information obtained from the clue should be considered case-insensitive, so for example "bill Green", "Bill GrEeN", and "Bill Green" should all be included in the new table.

18 |

Given the table Suspect, build the resulting table as follows: the table should have columns id, name and surname and its values should be ordered by the suspects' ids in ascending order.

19 |

Example

20 |

For the following table of Suspect

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
idnamesurnameheightweight
1JohnDoe16560
2BillGreen17067
3BaelfireGrehn17270
4BillGretan18555
5BrendonGrewn18050
6billGreen17250
72 |

the output should be

73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
idnamesurname
1JohnDoe
2BillGreen
4BillGretan
95 |

The 1st and the 2nd suspects are not taller than 170cm, and the 4th suspect's surname doesn't match the "Gre?n" pattern, so these suspects can't be guilty.

96 | 99 |
100 | -------------------------------------------------------------------------------- /12-suspectsInvestigation2/suspectsInvestigation2.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE suspectsInvestigation2() 2 | BEGIN 3 | SELECT id, name, surname 4 | FROM Suspect 5 | WHERE height <= 170 6 | OR name NOT LIKE 'B%' 7 | OR surname NOT LIKE 'Gre_n' 8 | ORDER BY id ASC; 9 | END -------------------------------------------------------------------------------- /13-securityBreach/README.md: -------------------------------------------------------------------------------- 1 |

Security Breach

2 |

source: codesignal.com 3 |

You are managing a large website that uses a special algorithm for user identification. In particular, it generates a unique attribute for each person based only on their first and last names and some additional metadata.

4 |

After analyzing the server logs today you found out that the website security has been breached and the data of some of your users might have been compromised.

5 |

The users' info is stored in the table users with the following structure:

6 | 11 |

It seems that only the users those attribute was generated by the old version of your special algorithm were affected. Such attributes have the following format (accurate to letter cases): <one or more arbitrary character>%<first name>_<second name>%<zero or more arbitrary characters>. It's your duty now to warn the users that have these attributes about possible risks.

12 |

Given the users table, compose the resulting table consisting only of the rows that contain affected users' info. The result should be sorted by the attributes in ascending order.

13 |

Example

14 |

For the following table users

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
first_namesecond_nameattribute
MikelCover%Mikel_Cover%
VicentaKravitz0%Vicenta_Kravitz%
ToshaCover02VO1aJ767GF7L186lpIfBR0fQ5406Q02YcpG42LDF4Bv26
ShayneDahlquist0R0V331K8Q7ypBi4Az3B6Nm0jCqUk%Shayne_Dahlquist%46E3O0u7t7
CarrolLlanes2mDIb1SdJne5wfH1Al32BE92r7j1d60PJ263b2vyPn3zxQ2P7sVOM26J11UT6W0Np
LizabethCoverd1gM87S0NEHp386jXOk0aDc7w8bx4u8q7D82ff2Z4YT43iLyZ39xYbEDXMk
MackChacefAnU49nMrmGu308627J7ne3qqqSPJDnq6dwW607lahNB5DinTR2Rkp549G7
VicentaMarchesekUJ3N67vLB07mQL9Ai7p18cXGzjdT32r8283ZQi
MikelKravitzPBX86iw1Ied87Z9OarE6sdSLdt%Mikel_Kravitz%W73XOY9YaOgi060r2x12D2EmD7
DeirdreChacePBX86iw1Ied87Z9OarE6sdSLdtDeirdrelChaceW73XOY9YaOgi060r2x12D2EmD7
JosphineArzatePwWD95BCKVYn5YD7iHLMa3HjP9tH%josphine_arzate%d2hNHNd3RpqfUREN47
DeirdreChaceryCE5FIyS8q54A5036luzVS91j6C7P76E9X0O58htzgthuX24LG%DEirdre_Chace%
JuliettaBeerTn35g5h51u7ltW946J
87 |

the output should be

88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 |
first_namesecond_nameattribute
VicentaKravitz0%Vicenta_Kravitz%
ShayneDahlquist0R0V331K8Q7ypBi4Az3B6Nm0jCqUk%Shayne_Dahlquist%46E3O0u7t7
MikelKravitzPBX86iw1Ied87Z9OarE6sdSLdt%Mikel_Kravitz%W73XOY9YaOgi060r2x12D2EmD7
110 | 113 |
114 | -------------------------------------------------------------------------------- /13-securityBreach/securityBreach.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE securityBreach() 2 | BEGIN 3 | SELECT first_name, second_name, attribute 4 | FROM users 5 | WHERE BINARY attribute LIKE CONCAT('_%', CONCAT('\%',first_name, '\_',second_name,'\%'), '%'); 6 | 7 | END -------------------------------------------------------------------------------- /14-testCheck/README.md: -------------------------------------------------------------------------------- 1 |

Test Check

2 |

source: codesignal.com 3 |

Your professor gave the class a bonus task: Write a program that will check the answers for the latest test. The program will be given a table answers with the following columns:

4 | 9 |

Your task is to return the table with a column id and a column checks, where for each answers id the following string should be returned:

10 | 15 |

Order the records in the answer table by id.

16 |

Example

17 |

For given table answers

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
idcorrect_answergiven_answer
1aa
2bNULL
3cb
40 |

the output should be

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
idchecks
1correct
2no answer
3incorrect
59 | 62 |
63 | -------------------------------------------------------------------------------- /14-testCheck/testCheck.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE testCheck() 2 | SELECT id, IF (given_answer is NULL, "no answer", IF(given_answer = correct_answer, "correct", "incorrect")) AS checks 3 | FROM answers 4 | ORDER BY id; 5 | -------------------------------------------------------------------------------- /15-expressionsVerification/README.md: -------------------------------------------------------------------------------- 1 |

Expressions Verification

2 |

source: codesignal.com 3 |

You're a math teacher at an elementary school. Today you taught your class basic arithmetic operations ("+", "-", "*", "/") and now you need to give the students some homework. You have a lot of expressions in the format a <operation> b = c, where a, b, and c are some integers and operation is one of the operations given above.

4 |

Information about these expressions is stored in the table expressions, which has the structure:

5 | 12 |

The homework you're going to give is simple: For each expression, the student needs to determine whether it's correct or not, i.e. whether it's true that the expression to the left of the = sign equals c.

13 |

Since you have many students and checking all their answers manually is a lot of work, you want to streamline the process by automatically identifying all the expressions that are correct. Given the table expressions, build the resulting table as follows: The table should have the same columns as the initial table does, but it should only contain those rows that represent correct expressions. The rows should be ordered by id.

14 |

Example

15 |

For the following table expressions

16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
idaboperationc
123+5
223+6
332/1
447*28
5542-27
630/0
67 |

the output should be

68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |
idaboperationc
123+5
447*28
91 |

Explanation:

92 | 100 | 103 |
104 | -------------------------------------------------------------------------------- /15-expressionsVerification/expressionsVerification.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE PROCEDURE expressionsVerification() 3 | BEGIN 4 | SELECT * 5 | FROM expressions 6 | WHERE (operation = '+' AND a+b = c) 7 | OR (operation = '-' AND a-b = c) 8 | OR (operation = '*' AND a*b = c) 9 | OR (operation = '/' AND a/b = c) 10 | ORDER BY id; 11 | 12 | END -------------------------------------------------------------------------------- /16-newsSubscribers/README.md: -------------------------------------------------------------------------------- 1 |

News Subscribers

2 |

source: codesignal.com 3 |

You are managing a small newspaper subscription service. Anyone who uses it can subscribe to a large number of different newspapers for a full year or just a half year.

4 |

The information about subscriptions is stored in the full_year and half_year tables, which have the following structures:

5 | 21 |

Given the full_year and half_year tables, compose the result as follows: The resulting table should have one column subscriber that contains all the distinct names of anyone who is subscribed to a newspaper with the word Daily in its name. The table should be sorted in ascending order by the subscribers' first names.

22 |

Example

23 |

The following tables full_year

24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
idnewspapersubscriber
1The Paragon HeraldCrissy Sepe
2The Daily ReporterTonie Moreton
3Morningtide DailyErwin Chitty
4Daily BreakfastTonie Moreton
5Independent WeeklyLavelle Phu
56 |

and half_year

57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
idnewspapersubscriber
1The Daily ReporterLavelle Phu
2Daily BreakfastTonie Moreton
3The Paragon HeraldLia Cover
4The Community GazetteLavelle Phu
5Nova DailyLia Cover
6Nova DailyJoya Buss
94 |

the output should be

95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 |
subscriber
Erwin Chitty
Joya Buss
Lavelle Phu
Lia Cover
Tonie Moreton
115 | 118 |
119 | -------------------------------------------------------------------------------- /16-newsSubscribers/newsSubscribers.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE newsSubscribers() 2 | BEGIN 3 | SELECT subscriber 4 | FROM full_year 5 | WHERE newspaper LIKE '%Daily%' 6 | UNION 7 | SELECT subscriber 8 | FROM half_year 9 | WHERE newspaper LIKE '%Daily%' 10 | ORDER BY subscriber; 11 | END -------------------------------------------------------------------------------- /17-countriesInfo/README.md: -------------------------------------------------------------------------------- 1 |

Countries Info

2 |

source: codesignal.com 3 |

Your friend wants to become a professional tour guide and travel all around the world. In pursuit of this dream, she enrolled in tour guide school. The professors in this school turned out to be very demanding, and one of them gave your friend a difficult assignment that she has to finish over the weekend.

4 |

Here's the task: Given a list of countries, your friend should calculate the average population and total population of all the countries in the list. To help her, you have decided to write a function that will calculate the required values for any number of countries. The countries table in which the countries are stored has the following structure:

5 | 10 |

Your task is to return a new table that contains the number of countries in the given list, along with their average and total population, in columns titled number, average and total.

11 |

Example

12 |

For the following table countries

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
namecontinentpopulation
GrenadaNorth America103328
MonacoEurope38400
San MarinoEurope33005
VanuatuAustralia277500
40 |

the output should be

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
numberaveragetotal
4113058.2500452233
53 | 56 |
57 | -------------------------------------------------------------------------------- /17-countriesInfo/countriesInfo.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE countriesInfo() 2 | BEGIN 3 | SELECT COUNT(name) as number, AVG(population) as average, sum(population) as total 4 | FROM countries; 5 | 6 | END -------------------------------------------------------------------------------- /18-itemCounts/README.md: -------------------------------------------------------------------------------- 1 |

Item Counts

2 |

source: codesignal.com 3 |

You recently started working in the IT department of a large store. You were put in charge of the inventory database availableItems, which has the following structure:

4 | 9 |

Note that it is possible for items that are of different types to have the same names.

10 |

One of the most common operations performed on this database is querying the number of specific items available at the store. Since the database is quite large, queries of this type can take up too much time. You have decided to solve this problem by creating a new table that contains item counts for all available items.

11 |

Given the availableItems table, compose a results table that has the following three columns: item_name, item_type and item_count, containing the names of the items, their types, and the amount of those items, respectively. The table should be sorted in ascending order by item type, with items of the same type sorted in ascending order by their names.

12 |

Example

13 |

For the following table availableItems

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 |
iditem_nameitem_type
1SafeDisk 4GBUSB drive
2SafeDisk 8GBUSB drive
3Cinco 50-PackDVD
4SafeDisk 4GBMemory card
5SafeDisk 8GBMemory card
6Cinco 30-PackDVD
7SafeDisk 4GBMemory card
8SafeDisk 4GBMemory card
9DiskHolderMisc
10Cinco 50-PackDVD
11SafeDisk 4GBUSB drive
12DiskCleaner ProMisc
81 |

the output should be

82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |
item_nameitem_typeitem_count
Cinco 30-PackDVD1
Cinco 50-PackDVD2
SafeDisk 4GBMemory card3
SafeDisk 8GBMemory card1
DiskCleaner ProMisc1
DiskHolderMisc1
SafeDisk 4GBUSB drive2
SafeDisk 8GBUSB drive1
129 | 132 |
-------------------------------------------------------------------------------- /18-itemCounts/itemCounts.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE itemCounts() 2 | BEGIN 3 | SELECT item_name, item_type, count(*) as item_count 4 | FROM availableItems 5 | GROUP BY item_name, item_type 6 | ORDER BY item_type, item_name; 7 | 8 | END -------------------------------------------------------------------------------- /19-usersByContinent/README.md: -------------------------------------------------------------------------------- 1 |

Users By Continent

2 |

source: codesignal.com 3 |

You are curious about the geographical distribution of CodeSignal users, so you have created a list of countries along with the number of registered users from each. Your task now is to calculate the number of users on each continent.

4 |

The information about the countries is stored in a table countries, which has 3 columns:

5 | 10 |

The answer should be a table with 2 columns, continent and users, sorted by the number of users in decreasing order.

11 |

Example

12 |

For the following table countries

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
countrycontinentusers
ArmeniaEurope1000
FranceEurope1300
RussiaEurope3000
USANorth America5000
40 |

the resulting table should be

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
continentusers
Europe5300
North America5000
55 | 58 |
59 | -------------------------------------------------------------------------------- /19-usersByContinent/usersByContinent.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE usersByContinent() 2 | BEGIN 3 | SELECT continent, sum(users) as users 4 | FROM countries 5 | GROUP BY continent 6 | ORDER BY users DESC; 7 | END -------------------------------------------------------------------------------- /20-movieDirectors/README.md: -------------------------------------------------------------------------------- 1 |

Movie Directors

2 |

source: codesignal.com 3 |

You want to expand your movie collection, but you don't really have any preferences so you're not sure where to start. After some consideration, you decide that you should start by finding more movies from award-winning directors whose movies you already own and who have shot a movie somewhat recently.

4 |

To find the directors whose movies you might want to consider watching in the first place, you've created a database of all the films you already own and stored them in a moviesInfo table, which has the following structure:

5 | 11 |

Given the moviesInfo table, compose the list of directors you should consider watching more movies from. The resulting table should have a single director column and contain the names of film directors such that:

12 | 16 |

The table should be sorted by the directors' names in ascending order.

17 |

Example

18 |

For the following table moviesInfo

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
titledirectoryearoscars
BoBoiBoy: The MovieNizam Razak20160
InceptionChristopher Nolan20104
InterstellarChristopher Nolan20141
Munna Bhai M.B.B.S.Rajkumar Hirani20030
My Dear BrotherErtem Egilmez19730
Rocky JohnG. Avildsen19763
The Nights of CabiriaFederico Fellini19571
The Sixth SenseM. Night Shyamalan19996
The Sixth SenseM. Night Shyamalan19996
Tokyo StoryYasujirô Ozu19530
YojimboAkira Kurosawa19611
93 |

the output should be

94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
director
Christopher Nolan
102 | 105 |
106 | -------------------------------------------------------------------------------- /20-movieDirectors/movieDirectors.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE movieDirectors() 2 | BEGIN 3 | SELECT director 4 | FROM moviesInfo 5 | WHERE year > 2000 6 | GROUP BY director HAVING SUM(oscars) > 2 7 | ORDER by director ASC; 8 | 9 | END -------------------------------------------------------------------------------- /21-travelDiary/README.md: -------------------------------------------------------------------------------- 1 |

Travel Diary

2 |

source: codesignal.com 3 |

You are an avid traveler and you've visited so many countries that when people ask you where you've been, you can't even remember all of them! Luckily, every time you travel somewhere you write down the trip information in your diary. Now you want to get a list of all the different countries that you have visited using the information in your diary.

4 |

The diary is represented as a table diary, which has the following columns:

5 | 10 |

Given this diary table, create a semicolon-separated list of all the distinct countries you've visited, sorted lexicographically, and put the list in a table that has a single countries column.

11 |

Example

12 |

For the following table diary

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
idtravel_datecountry
12008-05-12Ireland
22010-11-04France
32005-10-02Australia
42008-06-08Japan
52010-08-27Austria
62009-02-15France
50 |

the output should be

51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
countries
Australia;Austria;France;Ireland;Japan
59 | 62 |
-------------------------------------------------------------------------------- /21-travelDiary/travelDiary.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE travelDiary() 2 | BEGIN 3 | SELECT GROUP_CONCAT(DISTINCT country ORDER BY country SEPARATOR ';') as countries 4 | FROM diary; 5 | END -------------------------------------------------------------------------------- /22-soccerPlayers/README.md: -------------------------------------------------------------------------------- 1 |

Soccer SPlayers

2 |

source: codesignal.com 3 |

You have a table soccer_team that contains information about the players in your favorite soccer team. This table has the following structure:

4 | 10 |

Create a semicolon-separated list of all the players, sorted by their numbers, and put this list in a table under a column called players. The information about each player should have the following format: first_name surname #number.

11 |

Example

12 |

For the following table soccer_team

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 |
idfirst_namesurnameplayer_number
1 22 | AlexisSanchez7
2 28 | PetrCech33
3 34 | HectorBellerin24
4 40 | OlivierGiroud12
5 46 | TheoWalcott14
6 52 | SantiCazorla19
57 |

the output should be

58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
players
Alexis Sanchez #7; Oliver Giroud #12; Theo Walcott #14; Santi Cazorla #19; Hector Bellerin #24; Petr Cech #33
66 | 69 |
70 | 71 | -------------------------------------------------------------------------------- /22-soccerPlayers/soccerPlayers.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE soccerPlayers() 2 | BEGIN 3 | SELECT GROUP_CONCAT(CONCAT(first_name, ' ',surname,' #'), player_number order by player_number SEPARATOR '; ') as players 4 | FROM soccer_team; 5 | 6 | END -------------------------------------------------------------------------------- /23-marketReport/README.md: -------------------------------------------------------------------------------- 1 |

Market Report

2 |

source: codesignal.com 3 |

Your company is planning to expand internationally very soon. You have been tasked with preparing a report on foreign markets and potential competitors.

4 |

After some investigation, you've created a database containing a foreignCompetitors table, which has the following structure:

5 | 9 |

In your report, you need to include the number of competitors per country and an additional row at the bottom that contains a summary: ("Total:", total_number_of_competitors)

10 |

Given the foreignCompetitors table, compose the resulting table with two columns: country and competitors. The first column should contain the country name, and the second column should contain the number of competitors in this country. The table should be sorted by the country names in ascending order. In addition, it should have an extra row at the bottom with the summary, as described above.

11 |

Example

12 |

For the following table foreignCompetitors

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
competitorcountry
Acme CorpUSA
GLOBEXUSA
OpenmediaFrance
K-bamUSA
HatdrillUK
HexgreenGermany
D-ranronFrance
FaxlaSpain
51 |

the output should be

52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |
countrycompetitors
France2
Germany1
Spain1
UK1
USA3
Total:8
82 | 85 |
-------------------------------------------------------------------------------- /23-marketReport/marketReport.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE marketReport() 2 | BEGIN 3 | (SELECT country, COUNT(*) as competitors 4 | FROM foreignCompetitors 5 | GROUP BY country 6 | ORDER BY country 7 | LIMIT 100) 8 | UNION 9 | SELECT 'Total:', COUNT(competitor) as competitors 10 | FROM foreignCompetitors; 11 | END -------------------------------------------------------------------------------- /24-websiteHacking/README.md: -------------------------------------------------------------------------------- 1 |

Website Hacking

2 |

source: codesignal.com 3 |

Implement the missing code, denoted by ellipses. You may not modify the pre-existing code.
4 |

You've been dreaming about becoming a famous hacker all your life, and now it's time to make your dreams come true! You decided to start by finding a website that has some vulnerability, and you just found a doozy. This particular website has an open database users that contains information about the people using it. What's more, it stores the queries performed on this table on the client side, which makes it super simple to hack them.

5 |

The users table contains the following columns:

6 | 12 |

The query you have access to gathers some information about the users who have the "user" type. You don't want to get caught, so you want to carefully update it so that the query will return the records of all existing types.

13 |

Your task is to update the existing query. Note: You should add something to the query, but don't rewrite it.

14 |

Example

15 |

For the given table users

16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
idloginnametype
1Ann92Annuser
2Bob88Bobuser
3Carol412Caroladmin
4Deril39Deriladmin
5EvaGrinEvauser
54 |

the existing query returns the following table:

55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
idloginname
1Ann92Ann
2Bob88Bob
5EvaGrinEva
77 |

but the updated query should return the following one:

78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 |
idloginname
1Ann92Ann
2Bob88Bob
3Carol412Carol
4Deril39Deril
5EvaGrinEva
110 | 113 |
114 | -------------------------------------------------------------------------------- /24-websiteHacking/websiteHacking.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE websiteHacking() 2 | SELECT id,login,name 3 | FROM users 4 | WHERE type='user' 5 | OR type != 'user' 6 | ORDER BY id 7 | -------------------------------------------------------------------------------- /25-nullIntern/README.md: -------------------------------------------------------------------------------- 1 |

null Intern

2 |

source: codesignal.com 3 |

Your company hired an intern database engineer, who immediately started updating the data in the system. Unfortunately, he hasn't fully grasped the concept of NULL values yet and he performed some incorrect inserts and updates to the departments table, which has the following structure:

4 | 9 |

Now you have a table where the description column holds values such as '  NULL   ', NULL, 'nil' and ' - '. You need to find out exactly how many records in the table should have NULL in the description column, regardless of whether the intern input the value correctly or not.

10 |

He used the following values to indicate NULL:

11 | 17 |

Given the departments table, compose the resulting table with the single column number_of_nulls containing a single value: the number of rows in the departments table that are supposed to have NULL in the description.

18 |

Example

19 |

For the following table departments

20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
idnamedescription
1financeNULL
2marketing'   NULL'
3IT'not nil'
4accounting'-'
47 |

the output should be

48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
number_of_nulls
3
56 | 59 |
60 | -------------------------------------------------------------------------------- /25-nullIntern/nullIntern.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE nullIntern() 2 | BEGIN 3 | SELECT COUNT(id) as number_of_nulls 4 | FROM departments 5 | WHERE description IS NULL 6 | OR lower(trim(description)) = 'null' 7 | OR lower(trim(description)) = '-' 8 | OR lower(trim(description)) = 'nil'; 9 | END -------------------------------------------------------------------------------- /26-legsCount/README.md: -------------------------------------------------------------------------------- 1 |

Legs Count

2 |

source: codesignal.com 3 |

You really love counting stuff. In fact, right now you're sitting on a meadow and counting all the legs you see there! There are some people, some dogs, and some cats on the meadow. You're pretty confident that each human has 2 legs and that cats and dogs have 4 legs each.

4 |

The information about all the creatures on the meadow is stored in the table creatures. It has the following structure:

5 | 10 |

You want to calculate the total number of legs in the meadow. Given the table creatures, build a new table that only contains one column summary_legs and has only one row with the total number of legs that you can see.

11 |

Example

12 |

For the following table creatures

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
idnametype
1Mikehuman
2Mistycat
3Maxdog
4Tigerhuman
40 |

the output should be

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
summary_legs
12
49 |

There are 2 humans, 1 cat, and 1 dog, so there are 2 * 2 + 1 * 4 + 1 * 4 = 12 legs in total.

50 | 53 |
54 | -------------------------------------------------------------------------------- /26-legsCount/legsCount.sql: -------------------------------------------------------------------------------- 1 | DROP PROCEDURE IF EXISTS legsCount; 2 | CREATE PROCEDURE legsCount() 3 | SELECT (COUNT(type)*4 - (SELECT COUNT(type) FROM creatures WHERE type = 'human')*2)as summary_legs 4 | FROM creatures 5 | ORDER BY id; -------------------------------------------------------------------------------- /27-combinationLock/README.md: -------------------------------------------------------------------------------- 1 |

Combination Lock

2 |

source: codesignal.com 3 |

You returned from vacation with a huge suitcase full of presents. Unfortunately, you forgot the correct combination for the combination lock on the bag, and now you have to try all of them until you find the correct one. You're curious about how many possible combinations the lock has.

4 |

The combination lock consists of several rotating discs, where each disc has its own set of possible characters. You have a table discs which stores the information about these discs and has the following structure:

5 | 10 |

Calculate the total number of all possible combinations that the lock has, and return it as a table that has only one column combinations and one row.

11 |

Example

12 |

For the following table discs

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
idcharacterscolor
1codeblue
2fightswhite
30 |

the output should be

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
combinations
24
39 |

The set of possible characters for the first disc is equal to 4, and the set for the second disc is 6, so the total number of combinations is 4 * 6 = 24.

40 | 43 |
44 | -------------------------------------------------------------------------------- /27-combinationLock/combinationLock.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE combinationLock() 2 | BEGIN 3 | SET @comb = 1; 4 | SELECT max(@comb:= @comb*length(characters)) as combinations 5 | FROM discs; 6 | END 7 | -------------------------------------------------------------------------------- /28-interestClub/README.md: -------------------------------------------------------------------------------- 1 |

Interest Club

2 |

source: codesignal.com 3 |

Implement the missing code, denoted by ellipses. You may not modify the pre-existing code. 4 | CREATE PROCEDURE interestClub() 5 | SELECT name 6 | FROM people_interests 7 | WHERE interests & ... AND interests & ... 8 | ORDER BY name 9 |
10 |

You are the chairman of your university's drawing club, which isn't doing very well right now. The club meets two times a week to exchange drawing advice, talk about new techniques, and draw something together. But the members are starting to get bored during these meetings, so you've decided to add an additional activity to the routine.

11 |

In order to do this, you decided to collect information about the students, which is now stored in the table people_interests, which has the following columns:

12 | 16 |

This information gave you the idea that reading might be an interesting theme for the next meeting, so you announced that the next meeting will be reading-related. Now you're interested in the number of members that will come.

17 |

Given the people_interests table, find the people who will attend the next meeting, i.e. those who are fond of both drawing and reading. The resulting table should consist of a single name column, and the records should be sorted by people's names.

18 |

Example

19 |

For given table people_interests

20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
nameinterests
Augustcooking,juggling
Buddyreading,swimming,drawing,acting,dancing,videogaming
Davidjuggling,sculpting
Dennisswimming,cooking,fishkeeping
Jamesreading,drawing
46 |

the output should be

47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
name
Buddy
James
58 | 61 |
62 | -------------------------------------------------------------------------------- /28-interestClub/interestClub.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE interestClub() 2 | SELECT name 3 | FROM people_interests 4 | WHERE interests & 1<<0 AND interests & 1<<3 5 | ORDER BY name -------------------------------------------------------------------------------- /29-personalHobbies/README.md: -------------------------------------------------------------------------------- 1 |

Personal Hobbies

2 |

source: codesignal.com 3 |

You've been looking for new friends on the Internet. You just came across a cool website that helps people all over the world become friends by suggesting perfect friend candidates based on the information in users' profiles.

4 |

The system suggested some people for you to reach out to, and you're ready to make a move. However, you don't want to exercise your communication skills in vain, which is why prior to contacting a person you want to make sure you'll have something in common to talk about. The best option is to check whether they have the same hobbies you do, which are sports and reading.

5 |

You downloaded the list of suggested people and saved it in the people_hobbies table, which has the following structure:

6 | 10 |

Given the people_hobbies table, your goal is to return the sorted names of people who have sports and reading in their list of hobbies.

11 |

Example

12 |

For the given table people_hobbies

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
namehobbies
Adamswimming
Amyreading,sports,swimming
Carlfilmwatching,writing
Carolreading,swimming
Derilsports
Jakereading,sports,swimming
Lolareading,sports,painting
Ninasports,painting
Samsports
55 |

the output should be

56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
name
Amy
Lola
67 |

As you can see, only Amy and Lola have both reading and sports in their hobbies lists.

68 | 71 |
72 | -------------------------------------------------------------------------------- /29-personalHobbies/personalHobbies.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE personalHobbies() 2 | BEGIN 3 | SELECT name 4 | FROM people_hobbies 5 | WHERE hobbies LIKE "%reading%sports%"; 6 | END 7 | -------------------------------------------------------------------------------- /30-booksCatalogs/README.md: -------------------------------------------------------------------------------- 1 |

Books Catalogs

2 |

source: codesignal.com 3 |

You have your very own library at home, and it's getting bigger and bigger with each passing month. You've decided to create a database in which to store information about your books, in the hope that it will help you remember which books you have in your library.

4 |

Information about the books in your library is stored in the table catalogs, which contains the following columns:

5 | 21 |

Each catalog represents the work of one distinct <author> in your library. There is exactly one <catalog> element in each xml_doc, and the id for each book is unique.

22 |

Given the catalogs table, you want to find out which authors you have represented in your library. Your task is to create a new table with the author column that will contain all the distinct authors, sorted by their names.

23 |

Example

24 |

For given table catalogs

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 42 | 43 | 44 | 45 | 51 | 52 | 53 | 54 | 68 | 69 |
doc_idxml_doc
1
<catalog>
33 |  <book id="11">
34 |   <author>Chuck Palahniuk</author>
35 |   <title>Fight Club</title>
36 |  </book>
37 |  <book id="12">
38 |   <author>Chuck Palahniuk</author>
39 |   <title>Survivor</title>
40 |  </book>
41 | </catalog>
2
<catalog>
46 |  <book id="21">
47 |   <author>Bernard Werber</author>
48 |   <title>Les Thanatonautes</title>
49 |  </book>
50 | </catalog>
3
<catalog>
55 |  <book id="31">
56 |   <author>Boris Vian</author>
57 |   <title>The Big Sleep</title>
58 |  </book>
59 |  <book id="32">
60 |   <author>Boris Vian</author>
61 |   <title>The Lady in the Lake</title>
62 |  </book>
63 |  <book id="33">
64 |   <author>Boris Vian</author>
65 |   <title>The World of Null-A</title>
66 |  </book>
67 | </catalog>
70 |

the output should be

71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 |
author
Bernard Werber
Boris Vian
Chuck Palahniuk
85 | 88 |
89 | -------------------------------------------------------------------------------- /30-booksCatalogs/booksCatalogs.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE booksCatalogs() 2 | BEGIN 3 | SELECT ExtractValue(xml_doc, '/catalog/book[1]/author') as author 4 | FROM catalogs 5 | ORDER BY author; 6 | END 7 | -------------------------------------------------------------------------------- /31-habitatArea/README.md: -------------------------------------------------------------------------------- 1 |

Habitat Area

2 |

source: codesignal.com 3 |

As a young naturalist, you've been studying the inhabitants of the nearby woods for the past several months. You've just come across some footprints you've never seen before. To learn more about the habitat of the animal that left them, you marked the footprints locations on your map.

4 |

The information about the places where the animal left its footprints is stored in the table places. Here is its structure:

5 | 9 |

It is guaranteed that pairs (x, y) are unique.

10 |

Now you want to find the area of the animal's habitat. You decided that the convex hull of the marked points is a good first approximation of the habitat, so you want to find the area of this hull.

11 |

Given the places table, return a table that has only one column area and consists of a single row: the area of the convex hull. It is guaranteed that the resulting area is greater than 0.

12 |

Example

13 |

For the following table places

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
xy
00
12
21
51
52
40 |

the output should be

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
area
6.5
49 |

Here is an illustration of the given points and their convex hull:

50 |

Polygon Image

51 |

Note that you should return the exact answer without any trailing zeros.

52 | 55 |
56 | -------------------------------------------------------------------------------- /31-habitatArea/habitatArea.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE habitatArea() 2 | BEGIN 3 | SET @p = (SELECT CONCAT('MULTIPOINT(',GROUP_CONCAT(x,' ',y),')') FROM places); 4 | SELECT ST_Area(ST_ConvexHull(ST_GeomFromText(@p))) AS area; 5 | 6 | END 7 | -------------------------------------------------------------------------------- /32-orderOfSuccession/README.md: -------------------------------------------------------------------------------- 1 |

Order Of Succession

2 |

source: codesignal.com 3 |

The kingdom has been given terrible news: the King has passed away. While the nation is mourning, the noblemen need to decide who will take the throne next.

4 |

The late King had many children, and now it is necessary to determine their order of succession according to their seniority.

5 |

The list of the King's children is represented as a table Successors with the following attributes:

6 | 11 |

The resulting table should contain the names of the King's heirs in order of their succession to the throne as determined by their age, and preceded by their potential future titles (i.e. "King name" or "Queen name").

12 |

Example

13 |

For the following table Successors

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
namebirthdaygender
Amelia1711-06-10F
Anne1709-11-02F
Caroline1713-06-10F
Frederick1707-02-01M
Loisa1724-12-18F
Mary1723-03-05F
William1721-04-26M
56 |

The output should be

57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
name
King Frederick
Queen Anne
Queen Amelia
Queen Caroline
King William
Queen Mary
Queen Loisa
83 | 86 |
87 | -------------------------------------------------------------------------------- /32-orderOfSuccession/orderOfSuccession.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE orderOfSuccession() 2 | BEGIN 3 | SELECT 4 | (CASE 5 | WHEN gender = 'F' THEN concat('Queen ', name) 6 | ELSE concat('King ', name) 7 | END) as name 8 | FROM Successors 9 | ORDER BY birthday; 10 | END 11 | -------------------------------------------------------------------------------- /33-orderingEmails/README.md: -------------------------------------------------------------------------------- 1 |

Ordering Emails

2 |

source: codesignal.com 3 |

You've started to receive a lot of emails every day, and you decide to sort them in order to make it quicker to navigate through them.

4 |

Information about your emails is stored in a table emails, which has the following structure:

5 | 10 |

You decide to sort all the emails by their body sizes in descending order, because you think that the bigger an email is the more important it is. However, you don't like having the sizes written in bytes because they are usually too large and don't make much sense. You want them to be written in kilobytes (1 Kb = 210 bytes) and megabytes (1 Mb = 220 bytes) instead, rounded down if necessary. For example, 21432432 bytes is equal to 20 megabytes and 460912 bytes, so the result should be rounded down to 20 Mb.

11 |

Given the table emails, build a table as follows: The resulting table should have the columns id, email_title, and short_size, and should be sorted in descending order by the initial sizes of the emails. It is guaranteed that all the emails are of unique sizes, so there will not be any ties.

12 |

Example

13 |

For the following table emails

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
idemail_titlesize
1You won 1M dollars!21432432
2You are fired312342
3Black Friday is coming323
4Spam email23532
5Your requested backup234234324
46 |

the output should be

47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
idemail_titleshort_size
5Your requested backup223 Mb
1You won 1M dollars!20 Mb
2You are fired305 Kb
4Spam email22 Kb
3Black Friday is coming0 Kb
79 | 82 |
83 | -------------------------------------------------------------------------------- /33-orderingEmails/orderingEmails.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE orderingEmails() 2 | BEGIN 3 | SELECT id, email_title, 4 | CASE 5 | WHEN size >= 1048576 6 | THEN CONCAT(round(floor(size/POW(2,20))),' ','Mb') 7 | ELSE CONCAT(round(floor(size/POW(2,10))),' ','Kb') 8 | END as short_size 9 | FROM emails 10 | ORDER BY size DESC; 11 | END 12 | -------------------------------------------------------------------------------- /34-placesOfInterest/README.md: -------------------------------------------------------------------------------- 1 |

Places Of Interest

2 |

source: codesignal.com 3 |

You are trying to decide where you want to go on your vacation, so your travel agency has provided you with a database of possible destinations.

4 |

This database contains the table countryActivities, which has the following structure:

5 | 12 |

You want to see how many resorts in each country provide the activities you are interested in before you decide where to go on your vacation, but it's hard to do this using only the table provided by your travel agency. To make things easier, you have decided to create a new table with a better structure.

13 |

Given the countryActivities table, compose the resulting table with five columns: country, adventure_park, golf, river_cruise and kart_racing. The first column should contain the country name, while the second, third, fourth, and fifth columns should contain the number of resorts in the country that offer Adventure park, Golf, River cruise, and Kart racing, respectively. The table should be sorted by the country names in ascending order.

14 |

Example

15 |

For the following table countryActivities

16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
idcountryregionleisure_activity_typenumber_of_places
1FranceNormandyRiver cruise2
2GermanyBavariaGolf5
3GermanyBerlinAdventure park2
4FranceIle-de-FranceRiver cruise1
5SwedenStockholmRiver cruise3
6FranceNormandyKart racing4
67 |

the output should be

68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 |
countryadventure_parkgolfriver_cruisekart_racing
France0034
Germany2500
Sweden0030
98 | 101 |
102 | -------------------------------------------------------------------------------- /34-placesOfInterest/placesOfInterest.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE placesOfInterest() 2 | BEGIN 3 | SELECT country, 4 | SUM(CASE WHEN leisure_activity_type LIKE 'A%' THEN number_of_places ELSE 0 END) as adventure_park, 5 | SUM(CASE WHEN leisure_activity_type LIKE 'G%' THEN number_of_places ELSE 0 END) as golf, 6 | SUM(CASE WHEN leisure_activity_type LIKE 'R%' THEN number_of_places ELSE 0 END) as river_cruise, 7 | SUM(CASE WHEN leisure_activity_type LIKE 'K%' THEN number_of_places ELSE 0 END) as kart_racing 8 | FROM countryActivities 9 | GROUP BY country 10 | ORDER BY country; 11 | END 12 | -------------------------------------------------------------------------------- /35-soccerGameSeries/README.md: -------------------------------------------------------------------------------- 1 |

Soccer Game Series

2 |

source: codesignal.com 3 |

You have a table scores that contains information about a series of soccer games. Your goal is to determine the winner of the series. A team is declared the winner if it won more games than the other team. If both teams had the same number of wins, then the winner is determined by the better goal difference (the difference between the goals that a team scores and the goals that the opposing team scores on them over all the games). If the goal differences are equal, the winner is the team that scored more goals during away games (i.e. games when it was not the host team). The result is the index of the winning team. If the above criteria are not sufficient for determining the winner, return 0.

4 |

The scores table contains the following columns:

5 | 11 |

Your task is to return a new table with a single column winner, which can contain 1, 2, or 0.

12 |

Example

13 |

For given table scores

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
match_idfirst_team_scoresecond_team_scorematch_host
1321
2212
3121
4212
46 |

the output should be

47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
winner
1
55 |

The first team won 3 games out of 4, so it's the winner of the series.

56 | 59 |
60 | -------------------------------------------------------------------------------- /35-soccerGameSeries/soccerGameSeries.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/35-soccerGameSeries/soccerGameSeries.sql -------------------------------------------------------------------------------- /36-correctIPs/README.md: -------------------------------------------------------------------------------- 1 |

Correct IPs

2 |

source: codesignal.com 3 |

The company you work for has a database with the IP addresses of all the company's computers in it. When a new computer is purchased, an employee adds its IPv4 address to this database. Unfortunately, you've just discovered that there is no address validation, so some of the records are incorrect.

4 |

Now your boss wants you to write a program that will find and retain only the correct records from this table. A record is correct if the IP it contains is a valid IPv4 address, and either the first or the second component in the host part is a two-digit number.

5 |

The ips table contains the following columns:

6 | 10 |

Your task is to create a new table that contains only the correct records from the given ips table. This table should be sorted by id.

11 |

Example

12 |

For the given table ips

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
idip
4"1.1.1.1"
3"1.111.111.11"
2"11.11.11.11"
1"11.11.11.11.11.11"
5"11.11.11.111"
39 |

the output should be

40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
idip
2"11.11.11.11"
3"1.111.111.11"
5"11.11.11.111"
58 | 61 |
62 | -------------------------------------------------------------------------------- /36-correctIPs/correctIPs.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE correctIPs() 2 | BEGIN 3 | SELECT * 4 | FROM ips 5 | WHERE IS_IPV4(ip) 6 | AND length(SUBSTRING_INDEX(ip, '.', -2)) > 3 7 | ORDER BY id; 8 | END -------------------------------------------------------------------------------- /37-validPhoneNumbers/README.md: -------------------------------------------------------------------------------- 1 |

Valid PhoneNumbers

2 |

source: codesignal.com 3 |

You recently started a new job, and you were frustrated to discover that the company you joined has a very poorly written front-end client application. It doesn't even have validation checks for data entered by users! The biggest problem is with the phone_number field, which your company uses to send automatic notifications to users.

4 |

Your first task as a company employee is to retrieve all the valid records from the given table of phone numbers. The record is valid if its phone_number is a valid American or Canadian phone number, which means that it has a format of 1-###-###-#### or (1)###-###-####, where # stands for any digit from 0 to 9.

5 |

Information is stored in the table phone_numbers, which has the following fields:

6 | 11 |

You should return a new table that contains only the valid records from the phone_numbers table, sorted by the users' surnames.

12 |

Example

13 |

For the following table phone_numbers

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
namesurnamephone_number
CorneliusWalsh1-234-567-8910
FrankMcKenzie1-2345-678-911
JohnSmith(1)111-111-1111
LesterGoodwin(1)-111-111-1111
41 |

the output should be

42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
namesurnamephone_number
JohnSmith(1)111-111-1111
CorneliusWalsh1-234-567-8910
59 | 62 |
63 | -------------------------------------------------------------------------------- /37-validPhoneNumbers/validPhoneNumbers.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE validPhoneNumbers() 2 | BEGIN 3 | SELECT * 4 | FROM phone_numbers 5 | WHERE phone_number REGEXP '^((1-)|\\(1\\))[0-9]{3}-[0-9]{3}-[0-9]{4}$' 6 | ORDER BY surname; 7 | END 8 | -------------------------------------------------------------------------------- /38-importantEvents/README.md: -------------------------------------------------------------------------------- 1 |

Important Events

2 |

source: codesignal.com 3 |

You're very busy and have a lot of important events coming up. In order to ensure that you don't forget any of these events, you have decided to organize them.

4 |

The information about your events is stored in the table events, which has the structure:

5 | 11 |

After some thinking, you decide that it would be easier to navigate though your schedule if you could see all the events ordered by the weekday on which they are scheduled. In order to do so, you want to sort all the events by the weekdays of their event_dates, meaning that Monday events should come first, Tuesday events should come next, and so on, with Sunday events coming last. In the case of a tie, the participants should be a tie-breaker; an event with the largest number of participants should go first, because events with more attendees are more important. It is guaranteed that there are no events that have the same event_date and the same number of participants.

12 |

Given the table events, sort it as described above and return the resulting table.

13 |

Example

14 |

For the following table events

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
idnameevent_dateparticipants
1Dinner2016-11-273
2Comic-con2016-10-25100
3Christmas2016-12-315000
4Meeting2016-10-18300
47 |

the output should be

48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
idnameevent_dateparticipants
4Meeting2016-10-18300
2Comic-con2016-10-25100
3Christmas2016-12-315000
1Dinner2016-11-273
80 |

Meeting and Comic-con are both scheduled for Tuesdays, but Meeting is more important because its participants number is bigger. Christmas is scheduled for Saturday and Dinner is scheduled for Sunday.

81 | 84 |
85 | -------------------------------------------------------------------------------- /38-importantEvents/importantEvents.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE importantEvents() 2 | BEGIN 3 | SELECT * 4 | FROM events 5 | ORDER BY WEEKDAY(event_date), participants DESC; 6 | END 7 | -------------------------------------------------------------------------------- /39-dateFormatting/README.md: -------------------------------------------------------------------------------- 1 |

Date Formatting

2 |

source: codesignal.com 3 |

Your company's accounting department hasn't been doing great work lately, and they've been very sloppy when entering information into their database.

4 |

The information about each accounting document is stored in a documents table with 2 columns:

5 | 9 |

The omission of these leading zeros for days and months in the date column is making operations on the database prone to errors. To minimize the number of errors without changing the table structure, you need to translate all the dates to ISO format YYYY-MM-DD.

10 |

Given the documents table, return a table with one column date_iso that contains all the dates from documents sorted by the ids of the corresponding documents.

11 |

Example

12 |

For the following table documents

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
iddate_str
12000-1-1
22014-8-21
32002-03-07
42008-10-5
52016-12-17
39 |

the output should be

40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
date_iso
2000-01-01
2014-08-21
2002-03-07
2008-10-05
2016-12-17
60 | 63 |
64 | -------------------------------------------------------------------------------- /39-dateFormatting/dateFormatting.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE dateFormatting() 2 | BEGIN 3 | SELECT DATE_FORMAT(date_str, '%Y-%m-%d') AS date_iso 4 | FROM documents; 5 | END -------------------------------------------------------------------------------- /40-pastEvents/README.md: -------------------------------------------------------------------------------- 1 |

Past Events

2 |

source: codesignal.com 3 |

During the most recent social event you attended, you suddenly realized that you forgot your USB drive at a previous event. You're pretty sure that you had your flash drive with you just last week, which means that you probably lost it during one of the events of the last 7 days. You want to find all the events you attended during this period.

4 |

The list of events you've attended (including the most recent one) is stored in a table called Events. It has three columns:

5 | 10 |

You want to come up with the list of all the events you attended over the past 7 days, except for the very last one (since you know you lost your flash drive before then). Return this list as a table with columns name and event_date sorted by event dates in descending order.

11 |

It is guaranteed that there is at most one event on any given day.

12 |

Example

13 |

For the following table Events

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
idnameevent_date
1TGIF2016-11-18
2TGIF2016-11-11
3Weekly team meeting2016-11-07
4Weekly team meeting2016-11-14
40 |

the output should be

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
nameevent_date
Weekly team meeting2016-11-14
TGIF2016-11-11
53 | 56 |
57 | -------------------------------------------------------------------------------- /40-pastEvents/pastEvents.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE pastEvents() 2 | BEGIN 3 | SET @recent = (SELECT MAX(event_date) FROM Events); 4 | SELECT name, event_date 5 | FROM Events 6 | WHERE DATEDIFF(@recent, event_date) <= 7 7 | AND event_date != @recent 8 | ORDER BY event_date DESC; 9 | END -------------------------------------------------------------------------------- /41-netIncome/README.md: -------------------------------------------------------------------------------- 1 |

Net Income

2 |

source: codesignal.com 3 |

You own a small company, and you keep track of its income in the accounting table, which has the following structure:

4 | 9 |

You've decided to sell the company, and in order to make the offer more appealing to potential buyers you need to create a financial report.

10 |

Given the accounting table, compose the resulting table with three columns: year, quarter and net_profit. The first column should contain the year, the second one should contain the quarter of that year, and the third one should contain the net income (profit - loss difference) of your company during that period. The resulting table should be sorted by the year in ascending order. If there are several rows with the same year, sort them by the quarter in ascending order.

11 |

Don't include year/quarter in the answer if there is no entry for it in the accounting table.

12 |

Example

13 |

For the following table accounting

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
dateprofitloss
2006-01-0110015
2006-07-1540100
2006-08-015050
2006-11-1110050
2006-12-015080
2007-05-034216
51 |

the output should be

52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
yearquarternet_profit
2006185
20063-60
2006420
2007226
79 | 82 |
83 | 84 | -------------------------------------------------------------------------------- /41-netIncome/netIncome.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE netIncome() 2 | BEGIN 3 | SELECT YEAR(date) as year, QUARTER(date) as quarter, SUM(profit)-SUM(loss) as net_profit 4 | FROM accounting 5 | GROUP BY YEAR(date), QUARTER(date); 6 | END -------------------------------------------------------------------------------- /42-alarmClocks/README.md: -------------------------------------------------------------------------------- 1 |

Alarm Clocks

2 |

source: codesignal.com 3 |

You are developing an alarm clock app that works as follows: the user can set a date and a time, and the app will ring every week at the given time, starting at the given date until the end of the current year.

4 |

The starting date is the only record in the userInput table, which has the following structure:

5 | 8 |

Given the table, your task is to compose the resulting table with a single column alarm_date. This column should contain all dates (including the time) when the alarm clock will ring. The entries should be arranged in ascending chronological order.

9 |

Example

10 |

For the following table userInput

11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
input_date
2016-10-23 22:00:00
19 |

the output should be

20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
alarm_date
2016-10-23 22:00:00
2016-10-30 22:00:00
2016-11-06 22:00:00
2016-11-13 22:00:00
2016-11-20 22:00:00
2016-11-27 22:00:00
2016-12-04 22:00:00
2016-12-11 22:00:00
2016-12-18 22:00:00
2016-12-25 22:00:00
54 |

example

55 | 58 |
59 | -------------------------------------------------------------------------------- /42-alarmClocks/alarmClocks.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE alarmClocks() 2 | BEGIN 3 | DROP TABLE IF EXISTS output; 4 | CREATE TABLE output(alarm_date datetime); 5 | 6 | SET @intial_date = (SELECT input_date FROM userInput); 7 | SET @date = @intial_date; 8 | 9 | WHILE YEAR(@intial_date) = YEAR(@date) DO 10 | INSERT INTO output(alarm_date) SELECT @intial_date; 11 | SET @intial_date = DATE_ADD(@intial_date, INTERVAL 7 DAY); 12 | END WHILE; 13 | 14 | SELECT * FROM output; 15 | 16 | END 17 | -------------------------------------------------------------------------------- /43-companyEmployees/README.md: -------------------------------------------------------------------------------- 1 |

Company Employees

2 |

source: codesignal.com 3 |

You work at a small startup company that only has a handful of employees. Since the company is so small, some of the employees have to work in several departments at once. Because of this, information about groups of employees that work in the same departments is stored in two separate tables, departments and employees. The tables are structured as follows:

4 | 16 |

Given the tables departments and employees, you have to prepare a report about company employees and the departments in which they work. To do this, you simply combine the rows of the two tables, then sort the resulting rows first by the departments' names and then by the employees' names.

17 |

Example

18 |

For the following tables departments

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
dep_name
IT
PD
30 |

and employees:

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
emp_name
Donald Cole
James Richard
John Tucker
45 |

the output should be

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
dep_nameemp_name
ITDonald Cole
ITJames Richard
ITJohn Tucker
PDDonald Cole
PDJames Richard
PDJohn Tucker
76 | 79 |
80 | -------------------------------------------------------------------------------- /43-companyEmployees/companyEmployees.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE companyEmployees() 2 | BEGIN 3 | SELECT departments.dep_name, employees.emp_name 4 | FROM departments 5 | CROSS JOIN employees 6 | ORDER BY dep_name, emp_name; 7 | END 8 | -------------------------------------------------------------------------------- /44-scholarshipsDistribution/README.md: -------------------------------------------------------------------------------- 1 |

scholarshipsDistribution

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /44-scholarshipsDistribution/scholarshipsDistribution.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE scholarshipsDistribution() 2 | BEGIN 3 | SELECT candidates.candidate_id as student_id 4 | FROM candidates 5 | LEFT JOIN detentions 6 | ON candidates.candidate_id = detentions.student_id 7 | WHERE detentions.student_id IS NULL; 8 | END 9 | -------------------------------------------------------------------------------- /45-userCountries/README.md: -------------------------------------------------------------------------------- 1 |

User Countries

2 |

source: codesignal.com 3 |

You are really interested in statistics, and your new project is to gather some information about the users of a big social network. More specifically, you want to know which countries these users are from. Using the social network's API, you managed to collect enough data to compose two tables users and cities, which have the following structures:

4 | 18 |

Given the tables users and cities, build the resulting table so that it consists of the columns id and country. The table should consist of user ids, and for each user the country where they live should be given in the country column. If a user's city is missing from the cities table, the country column should contain "unknown" instead.

19 |

Return the table sorted by users' ids.

20 |

Example

21 |

For the following table users

22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
idcity
1San Francisco
2Moscow
3London
4Washington
5New York
6Saint Petersburg
7Helsinki
56 |

and the following table cities

57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
citycountry
MoscowRussia
Saint PetersburgRussia
San FranciscoUSA
WashingtonUSA
New YorkUSA
LondonEngland
87 |

the output should be

88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
idcountry
1USA
2Russia
3England
4USA
5USA
6Russia
7unknown
122 | 125 |
126 | -------------------------------------------------------------------------------- /45-userCountries/userCountries.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE userCountries() 2 | BEGIN 3 | SELECT users.id, IFNULL(cities.country, 'unknown') as country 4 | FROM users 5 | LEFT JOIN cities 6 | ON users.city = cities.city 7 | ORDER BY 1; 8 | END 9 | -------------------------------------------------------------------------------- /46-placesOfInterestPairs/README.md: -------------------------------------------------------------------------------- 1 |

Places Of InterestPairs

2 |

source: codesignal.com 3 |

You're going on vacation in a big city, and you've prepared a list of all the sights you'd like to visit. As you don't have much time and can't spend a whole day at one interesting place, you want to visit several sights per day and walk from one site to another. But walking a long distance might be boring, so you won't walk between two places if the distance between them is 5 km or more.

4 |

To find the route that you should take, you are going to find all pairs of places that are less than 5 km from each other.

5 |

The places of interests are stored in a table sights, which has the following attributes:

6 | 12 |

The distance between the places is calculated with the assumption that they are just points on a 2D map.

13 |

Given the sights table, find all pairs of places that are less than 5 km from each other and return them as a table with the columns place1 and place2. Sort them in lexicographical order. The places in the pairs should also be sorted lexicographically.

14 |

Example

15 |

For the following table sights

16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
idnamexy
1Tower of London51508.026-7.5939
2Trafalgar Square51508.040-12.7899
3London Eye51503.538-11.9371
4The Shard51504.533-8.6028
48 |

the output should be

49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
place1place2
London EyeThe Shard
London EyeTrafalgar Square
The ShardTower of London
67 |

https://codesignal.s3.amazonaws.com/tasks/placesOfInterestPairs/img/ex.png?_tm=1551433043558"

68 | 71 |
72 | -------------------------------------------------------------------------------- /46-placesOfInterestPairs/placesOfInterestPairs.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE placesOfInterestPairs() 2 | BEGIN 3 | SELECT a.name as place1, b.name as place2 4 | FROM sights a 5 | JOIN sights b ON(a.name < b.name) 6 | WHERE ST_DISTANCE(POINT(a.`x`,a.`y`), POINT(b.`x`, b.`y`)) < 5 7 | ORDER BY place1, place2; 8 | END 9 | -------------------------------------------------------------------------------- /47-localCalendar/README.md: -------------------------------------------------------------------------------- 1 |

Local Calendar

2 |

source: codesignal.com 3 |

You are developing a calendar application that will allow users to schedule various events on different dates. The dates are all stored in the server local time as a DATETIME. You want to display the dates using the settings specified by the user.

4 |

Event dates and user settings are stored in the events and settings tables, which have the following structures:

5 | 21 |

The displayed dates should have the format yyyy-mm-dd hh:mm if the user's clock has 24 hours. Otherwise, the format should be yyyy-mm-dd hh:mm <p>, where <p> is either AM or PM depending on the time.

22 |

Given the events and settings tables, compose the result as follows: The resulting table should have two columns, event_id and formatted_date, that contain the event IDs and the formatted event dates according to settings of the user who scheduled that event, respectively. The table should be sorted in ascending order by the event IDs.

23 |

Example

24 |

The following tables events

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
event_iddateuser_id
12011-11-11 13:37:004242
22012-12-12 04:04:004987
32016-01-01 11:19:004242
42011-11-11 13:37:004987
52 |

and settings

53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |
user_idtimeshifthours
13024
4242024
49876012
75 |

the output should be

76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 |
event_idformatted_date
12011-11-11 13:37
22012-12-12 05:04 AM
32016-01-01 11:19
42011-11-11 02:37 PM
98 | 101 |
102 | -------------------------------------------------------------------------------- /47-localCalendar/localCalendar.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE localCalendar() 2 | BEGIN 3 | SELECT event_id, IF(hours=12, DATE_FORMAT(DATE_ADD(date, INTERVAL timeshift MINUTE), '%Y-%m-%d %h:%i %p') , DATE_FORMAT(DATE_ADD(date, INTERVAL timeshift MINUTE), '%Y-%m-%d %H:%i')) formatted_date 4 | FROM events 5 | JOIN settings USING (user_id); 6 | END 7 | -------------------------------------------------------------------------------- /48-routeLength/README.md: -------------------------------------------------------------------------------- 1 |

Route Length

2 |

source: codesignal.com 3 |

You've been traveling all over the world for the past year, and now it's time for you to come home. You marked each city that you visited on a map in the order that you visited them, and wrote down the cities' coordinates. For the sake of simplicity, the cities are assigned coordinates on a plane map, so they can be written as (x, y).

4 |

The information about the cities you visited is stored in the table cities, which has the structure:

5 | 10 |

Now that your journey is over, you're curious about the distance you covered. Given the cities table, your task is to calculate the total length of your route as follows: First, calculate the Euclidean distance between the first and second cities, then add it to the distance between the second and the third cities, and so on.

11 |

Return the table with a single total column containing only one row which contains the total length of your route, calculated as described above.

12 |

Example

13 |

For the following table cities

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
idxy
100
211
322
442
41 |

the output should be

42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
total
4.828427125
50 |

Here is how the answer was calculated:
51 | distance(0, 0, 1, 1) + distance(1, 1, 2, 2) + distance(2, 2, 4, 2) = sqrt(2) + sqrt(2) + 2 = 4.828427125.

52 |

The answer should be rounded to exactly 9 digits after the decimal point.

53 | 56 |
57 | -------------------------------------------------------------------------------- /48-routeLength/routeLength.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/48-routeLength/routeLength.sql -------------------------------------------------------------------------------- /49-currencyCodes/README.md: -------------------------------------------------------------------------------- 1 |

Currency Codes

2 |

source: codesignal.com 3 |

You are developing an application for working with different currencies. You've decided to represent each currency using three letter codes from ISO 4217.

4 |

You've parsed some data that you found on the Internet and stored it in a currencies table, which has the following structure:

5 | 9 |

Unfortunately, your parser didn't check the length of the codes and some erroneous data got into the table by mistake.

10 |

Your task is to delete all rows from the currencies table in which code is not exactly three letters long.

11 |

Example

12 |

The following table currencies

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
codecountry
ADAndorra
AUDAustralia
BRLBrazil
MXNMexico
RUBRussia
RURRussia
SEKRSweden
USDUSA
51 |

should become

52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |
codecountry
AUDAustralia
BRLBrazil
MXNMexico
RUBRussia
RURRussia
USDUSA
82 | 85 |
86 | -------------------------------------------------------------------------------- /49-currencyCodes/currencyCodes.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE currencyCodes() 2 | BEGIN 3 | DELETE FROM currencies 4 | WHERE LENGTH(code) <> 3; 5 | 6 | SELECT * FROM currencies ORDER BY code; 7 | END 8 | -------------------------------------------------------------------------------- /50-coursesDistribution/README.md: -------------------------------------------------------------------------------- 1 |

Courses Distribution

2 |

source: codesignal.com 3 |

You work with a professor of applied mathematics and informatics to create and distribute this year's plan of courses for students.
4 | You were almost finished when you noticed that a couple of fixes yet need to be done. There are courses which names' are marked as '-toremove', so you decided to remove them permanently. Prior to removing them, you'd like to make sure that deleting a course would also remove it from all the related tables automatically.

5 |

All courses are stored in courses table that has the following structure:

6 | 11 |

There are also groupcourses and groupexams tables which represent courses assigned to groups and examination dates of courses for each group, respectively. Here are their structures:

12 | 27 |

Given courses, groupcourses and groupexams tables you need to properly set up foreign keys, so that after a record is deleted from the courses table, records that correspond to the deleted course are also deleted from groupcourses and groupexams. Please note that groupexams can only contain pairs from groupcourses and there can be multiple exam dates for the same group_id, course_id combination. It is guaranteed that adding correct foreign keys won't raise any errors.

28 |

Example

29 |

For the following tables courses

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
idnamedescription
1Linear algebraBasis of matrix theory and linear algebra
2GeometryNULL
3Determinants and matricesNULL
4Matlab-toremoveMatlab 7
57 |

groupcourses

58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
group_idcourse_id
11
12
13
21
24
84 |

and groupexams

85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
dategroup_idcourse_id
2010-01-1011
2010-01-1112
2010-01-1224
107 |

the final result should be

108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 |
group_idcourse_id
11
12
13
21
130 | 133 |
134 | -------------------------------------------------------------------------------- /50-coursesDistribution/coursesDistribution.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE coursesDistribution() 2 | BEGIN 3 | ALTER TABLE groupcourses ADD FOREIGN KEY (course_id) 4 | REFERENCES courses(id) ON DELETE CASCADE; 5 | 6 | ALTER TABLE groupexams ADD FOREIGN KEY (course_id) 7 | REFERENCES courses(id) ON DELETE CASCADE; 8 | 9 | DELETE FROM courses WHERE name LIKE '%-toremove'; 10 | 11 | 12 | SELECT group_id, course_id 13 | FROM groupcourses 14 | UNION 15 | SELECT group_id, course_id 16 | FROM groupexams 17 | ORDER BY group_id, course_id; 18 | END 19 | -------------------------------------------------------------------------------- /51-nicknames/README.md: -------------------------------------------------------------------------------- 1 |

Nicknames

2 |

source: codesignal.com 3 |

You've just opened a registration for the online game you are about to finish developing.
4 | Everyone who wanted to reserve their nicknames for the release of the game had to submit their info using a special form on your website.

5 |

The reserved nicknames were stored in the reservedNicknames table with the following structure:

6 | 10 |

When you started going through these nicknames you realized that you forgot one important thing: all nicknames should contain exactly 8 characters.
11 | You have no time to fix this issue properly right now, so you decided to just add rename - to the invalid nicknames with corresponding ids so it would be easier for you to deal with them latter.

12 |

Given the reservedNicknames table, change all rows with invalid nicknames by prepending rename - to both nickname and id.

13 |

Example

14 |

The following table reservedNicknames

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
idnickname
id001alex1990
id142killer007
id15674prohunter
id4242acc0rdin
id616Zoneg
id9999butch
45 |

should become

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
idnickname
id001alex1990
id4242acc0rdin
rename - id142rename - killer007
rename - id15674rename - prohunter
rename - id616rename - Zoneg
rename - id9999rename - butch
76 | 79 |
80 | -------------------------------------------------------------------------------- /51-nicknames/nicknames.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE nicknames() 2 | BEGIN 3 | UPDATE reservedNicknames 4 | SET nickname = CONCAT('rename - ',nickname), id = CONCAT('rename - ', id) 5 | WHERE LENGTH(nickname) <> 8; 6 | 7 | SELECT * FROM reservedNicknames ORDER BY id; 8 | END 9 | -------------------------------------------------------------------------------- /52-tableSecurity/README.md: -------------------------------------------------------------------------------- 1 |

Table Security

2 |

source: codesignal.com 3 |

As the head of a company you decided that it's time to introduce access control and to restrict access to employees table for all the employees. The table has the following structure:

4 | 10 |

As a first step towards improving security you decided to create a view which would be used by the employees instead of direct access to the table.

11 |

Create a view which will select all the columns from the employees table but leave only id and name intact. date_joined column should contain the year the employee joined the company, and salary column should be filled with - (single dashes).

12 |

Example

13 |

The following table employees

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
idnamedate_joinedsalary
1Farah Dahlquist2006-03-052000
2Yessenia Lininger2008-04-112500
3Justin Penrose2009-12-122400
4Josphine Clickner2007-07-253000
5Linwood Mcquiston2011-01-154000
52 |

the output should be

53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |
idnamedate_joinedsalary
1Farah Dahlquist2006-
2Yessenia Lininger2008-
3Justin Penrose2009-
4Josphine Clickner2007-
5Linwood Mcquiston2011-
91 | 94 |
95 | -------------------------------------------------------------------------------- /52-tableSecurity/tableSecurity.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE tableSecurity() 2 | BEGIN 3 | CREATE OR REPLACE VIEW emp 4 | AS SELECT id, name, YEAR(date_joined) as date_joined, '-' as salary FROM employees; 5 | 6 | SELECT id, name, date_joined, salary 7 | FROM emp 8 | ORDER BY id; 9 | END 10 | -------------------------------------------------------------------------------- /53-officeBranches/README.md: -------------------------------------------------------------------------------- 1 |

Office Branches

2 |

source: codesignal.com 3 |

In order to optimize your business, you've decided to merge a couple of your office branches and get rid of the outdated branch types.

4 |

The existing office branches and branch types are stored in the tables branches and branch_types, respectively. The tables have the following structures:

5 | 20 |

You've decided to start small. As your first step, you want to delete the outdated branch types, all of which end with -outdated, from the branch_types table.

21 |

For now, you want to keep all the branches with the deleted branch types in the branches table, but to differentiate them you will set their branchtype_id to NULL. Update the database to make the required changes happen automatically when a record is deleted from branch_types.

22 |

Example

23 |

For the following tables branches

24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
branch_idnamebranchtype_id
1Frankfurt branch2
2Paris branch3
3New York branch2
4Madrid branch1
51 |

and branch_types

52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
idname
1Small-outdated
2Big
3Medium
70 |

the output should be

71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 |
branch_idnamebranchtype_id
1Frankfurt branch2
2Paris branch3
3New York branch2
4Madrid branchNULL
98 | 101 |
102 | -------------------------------------------------------------------------------- /53-officeBranches/officeBranches.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE officeBranches() 2 | BEGIN 3 | ALTER TABLE branches ADD FOREIGN KEY (branchtype_id) 4 | REFERENCES branch_types(id) ON DELETE SET NULL; 5 | 6 | DELETE FROM branch_types WHERE name LIKE '%-outdated'; 7 | 8 | SELECT * FROM branches 9 | ORDER BY branch_id; 10 | END 11 | -------------------------------------------------------------------------------- /54-restaurantInfo/README.md: -------------------------------------------------------------------------------- 1 |

Restaurant Info

2 |

source: codesignal.com 3 |

You are managing a restaurant recommendation service that has recently started to gain popularity.
4 | The information about the restaurants is currently stored in the restaurants table with the following structure:

5 | 9 |

As the table grew you decided to extend it, in particular add the description (VARCHAR(100), the description of the restaurant) and active (INT, 0 or 1 if it works or closed respectively) columns.

10 |

Add these two new columns to the restaurants table using the following rules for all records:

11 | 15 |

Example

16 |

The following table restaurants

17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
idname
1The Big City Barbecue
2Roadhouse
3Hibiscus
4The Waterfront Courtyard
5The Royal Spices
43 |

should become

44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |
idnamedescriptionactive
1The Big City BarbecueTBD1
2RoadhouseTBD1
3HibiscusTBD1
4The Waterfront CourtyardTBD1
5The Royal SpicesTBD1
82 | 85 |
86 | -------------------------------------------------------------------------------- /54-restaurantInfo/restaurantInfo.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE restaurantInfo() 2 | BEGIN 3 | ALTER TABLE restaurants 4 | ADD COLUMN description VARCHAR(100) DEFAULT 'TBD', 5 | ADD COLUMN active TINYINT(1) DEFAULT 1; 6 | 7 | SELECT * FROM restaurants ORDER BY id; 8 | END 9 | -------------------------------------------------------------------------------- /55-studentsInClubs/README.md: -------------------------------------------------------------------------------- 1 |

Students In Clubs

2 |

source: codesignal.com 3 |

At the beginning of this academic year you composed a list of clubs and a list of their members. The gathered information is stored in your local database in two tables that have the following structures:

4 | 19 |

Each student can be a member only of a single club, and it is prohibited to drop a club until the year is over. However, several clubs were closed due to low attendance, and you need to update your database to reflect that. You have already updated the clubs table, and now the students table should be updated as well.

20 |

Given the clubs and students tables, return a table containing the records from students that have club_id equal to some id of clubs. The table should be sorted by students' ids.

21 |

Example

22 |

For the following table students

23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
idnameclub_id
3Richard Gear23
6Jennifer Offencerence11
14Obiten Kenobi87
36Closece87
50 |

and clubs

51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
idname
23Theater club
64Soccer club
87Glee club
69 |

the output should be

70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 |
idnameclub_id
3Richard Gear23
14Obiten Kenobi87
36Closece87
92 | 95 |
96 | -------------------------------------------------------------------------------- /55-studentsInClubs/studentsInClubs.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE studentsInClubs() 2 | SELECT * FROM students 3 | WHERE EXISTS ( 4 | SELECT * FROM clubs WHERE clubs.id = students.club_id 5 | ) 6 | ORDER BY students.id; 7 | -------------------------------------------------------------------------------- /56-emptyDepartments/README.md: -------------------------------------------------------------------------------- 1 |

Empty Departments

2 |

source: codesignal.com 3 |

You've just started working for a large and successful company, and it's come as a shock to find that the records about the company's internal organization haven't been updated for ages. Some employees have changed their departments and some have resigned, and consequently, there are some departments that have no employees in them. You want to identify these departments.

4 |

Information about employees and departments is stored in two tables, employees and departments, which have the following structure:

5 | 20 |

Given the tables employees and departments, build a table with only one column, dep_name, which contains all the departments in which there are no employees, sorted by id.

21 |

Example

22 |

For the following tables departments

23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
iddep_name
1IT
2HR
3Sales
4Warehousing
45 |

and employees

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
idfull_namedepartment
1James Miller1
2Joseph Harvey1
3Anna Lawson2
4Arthur Saunders3
73 |

the output should be

74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |
dep_name
Warehousing
82 | 85 |
86 | -------------------------------------------------------------------------------- /56-emptyDepartments/emptyDepartments.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE emptyDepartments() 2 | BEGIN 3 | SELECT dep_name 4 | FROM departments 5 | WHERE dep_name NOT IN (SELECT dep_name from departments, employees WHERE departments.id = employees.department); 6 | END 7 | -------------------------------------------------------------------------------- /57-sunnyHolidays/README.md: -------------------------------------------------------------------------------- 1 |

Sunny Holidays

2 |

source: codesignal.com 3 |

Winter is coming, and it's going to be great! The weather forecasters promise that it's going to be snowy, and there are a bunch of holidays so you'll be able to spend entire days on the slopes. You want to know how many perfect ski days, which are sunny days that fall on holidays, there are going to be this winter.

4 |

You downloaded information about the weather forecast and saved it as the table weather, which consists of a single sunny_date column of type DATE. Information about the upcoming holidays is stored in the table holidays, which consists of a holiday_date column of type DATE. It is guaranteed that the elements of each table are unique.

5 |

Given the holidays and weather tables, return the dates that are present in both (i.e., their intersection). The resulting table should consist of a single ski_date column, and its elements should be sorted in ascending order.

6 |

Example

7 |

For the following tables holidays

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
holiday_date
2016-12-31
2017-01-02
2017-01-03
2017-01-20
25 |

and weather

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
sunny_date
2016-12-31
2016-12-25
2017-02-01
2017-01-02
2016-11-27
2017-01-01
49 |

the output should be

50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
ski_date
2016-12-31
2017-01-02
61 |

The dates in this example are given in YYYY-MM-DD format.

62 | 65 |
66 | -------------------------------------------------------------------------------- /57-sunnyHolidays/sunnyHolidays.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE sunnyHolidays() 2 | BEGIN 3 | SELECT holiday_date AS ski_date 4 | FROM holidays 5 | INNER JOIN weather ON holiday_date = sunny_date; 6 | END 7 | -------------------------------------------------------------------------------- /58-closestCells/README.md: -------------------------------------------------------------------------------- 1 |

Closest Cells

2 |

source: codesignal.com 3 |

You are playing a game on a rectangular checkerboard with a specific set of rules.
4 | Each game piece has a unique id and each cell on the board is defined by its x and y coordinates.

5 |

The current positions of your pieces on the board are stored in the positions table with the following structure:

6 | 11 |

In this game each piece on the board is said to defend its nearest neighbor. The distance between two pieces is calculated simply as the distance between the points (x1, y1) and (x2, y2), where (x1, y1) and (x2, y2) are the coordinates of the cells occupied by the first and the second piece, respectively.
12 | You thought it might be good idea to find what piece each of the game pieces defends.

13 |

Given the positions table, compose the resulting table with two columns: id1 and id2, such that on each row the piece with id id1 defends the piece with id2 (i.e. id2 is the closest to id1 piece).
14 | The table should be sorted by the values of id1 in ascending order.
15 | It's guaranteed that for each piece there is only one other piece closest to it.

16 |

Example

17 |

For the following table positions

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
idxy
100
220
343
421
45 |

the output should be

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
id1id2
12
24
34
42
68 |

example

69 | 72 |
73 | -------------------------------------------------------------------------------- /58-closestCells/closestCells.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/58-closestCells/closestCells.sql -------------------------------------------------------------------------------- /59-top5AverageGrade/README.md: -------------------------------------------------------------------------------- 1 |

Top 5 AverageGrade

2 |

source: codesignal.com 3 |

You're doing research about academic achievement, and you're studying one particular group of students at a local university. Find the average grade of the five most successful students in this group.

4 |

The information about the students' grades is stored in a table called students, which has the following attributes:

5 | 10 |

The result should be a table with one column average_grade and one row that contains the average grade of the five students with the highest grades. The answer should be formatted to 2 digits after the decimal point. It is guaranteed that the five most successful students can be uniquely identified.

11 |

Example

12 |

For the following table students

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
student_idstudent_namegrade
1Oliver Smith3.2
2Jacob Bell2.9
3William Thompson3.1
4Sophie Clark3.5
5Daniel Palmer3.6
6Emily Morris4.0
7Zachary Mills2.5
55 |

the output should be

56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
average_grade
3.48
64 |

The top 5 grades for this group are 4.0, 3.6, 3.5, 3.2, and 3.1, so their sum is equal to 17.4 and 17.4 / 5 = 3.48.

65 | 68 |
69 | -------------------------------------------------------------------------------- /59-top5AverageGrade/top5AverageGrade.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE top5AverageGrade() 2 | BEGIN 3 | SELECT ROUND(AVG(grade), 2) as average_grade 4 | FROM (SELECT grade FROM students ORDER BY grade DESC LIMIT 5) top5; 5 | END 6 | -------------------------------------------------------------------------------- /60-salaryDifference/README.md: -------------------------------------------------------------------------------- 1 |

Salary Difference

2 |

source: codesignal.com 3 |

There are many employees at your company, with a wide range of salaries. You've decided to find out the difference in salary between the employees who make the most and the employees who make the least.

4 |

You store information about your employees in the table employees, which has the structure:

5 | 10 |

The difference between the sum of the highest salaries and the sum of lowest salaries will give you the information you want. So, given the table employees, build the resulting table as follows: The table should contain only one column difference and only one row, which will contain the difference between sum of the highest and the sum of lowest salaries. If employees table is empty, the difference should be equal 0.

11 |

Example

12 |

For the following table employees

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
idnamesalary
1John1200
2Bill1000
3Mike1300
4Katy1200
5Brendon1300
6Amanda900
50 |

the output should be

51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
difference
1700
59 |

There are two highest salaries (1300) and one lowest salary (900). 1300 * 2 - 900 * 1 = 1700.

60 | 63 |
64 | -------------------------------------------------------------------------------- /60-salaryDifference/salaryDifference.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE salaryDifference() 2 | BEGIN 3 | SET @maxSal = (SELECT max(salary) FROM employees); 4 | SET @minSal = (SELECT min(salary) FROM employees); 5 | SET @maxSum = (SELECT @maxSal * COUNT(*) FROM employees WHERE salary =@maxSal); 6 | SET @minSum = (SELECT @minSal * COUNT(*) FROM employees WHERE salary =@minSal); 7 | 8 | SELECT IFNULL(@maxSum - @minSum, 0) as difference; 9 | END 10 | -------------------------------------------------------------------------------- /61-recentHires/README.md: -------------------------------------------------------------------------------- 1 |

Recent Hires

2 |

source: codesignal.com 3 |

Your company has many different departments. Information about the employees working in these departments is stored in the pr_department, it_department, and sales_department tables, which have the following structures:

4 | 27 |

Your task is to prepare a report that has the names of all the employees who were hired recently.

28 |

Given the pr_department, it_department, and sales_department tables, compose the result as follows: The resulting table should have one column names that contains the names of the last five people to join each department. The names of the employees from the pr_department should come first, followed by the it_department, and the sales_department will come last. The names of employees who work in the same department should be sorted in ascending order.

29 |

Example

30 |

The following tables pr_department

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
idnamedate_joined
2Bertha Neiman2010-12-15
3Melissa Chace2012-08-14
4Doyle Wiste2015-01-02
8Libbie Troy2016-03-04
15Noreen Bonner2012-07-07
42Farah Dahlquist2006-12-12
68 |

it_department

69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 |
idnamedate_joined
1Farah Dahlquist2017-01-15
2Mohammed Claycomb2016-06-11
3Allen Reger2015-08-12
5Jacque Fuhr2013-04-01
4Joya Buss2011-11-11
6Leonia Maultsby2009-02-02
7Oliva Mcgarry2008-05-05
111 |

and sales_department

112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |
idnamedate_joined
3Jayne Kravitz2009-09-09
4Joya Buss2008-08-08
7Edmond Kind2007-07-07
134 |

the output should be

135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 |
names
Bertha Neiman
Doyle Wiste
Libbie Troy
Melissa Chace
Noreen Bonner
Allen Reger
Farah Dahlquist
Jacque Fuhr
Joya Buss
Mohammed Claycomb
Edmond Kind
Jayne Kravitz
Joya Buss
179 | 182 |
183 | -------------------------------------------------------------------------------- /61-recentHires/recentHires.sql: -------------------------------------------------------------------------------- 1 | CREATE PROCEDURE recentHires() 2 | BEGIN 3 | SELECT name as names FROM ( 4 | 5 | (SELECT name, 1 as filter FROM (SELECT name from pr_department ORDER BY date_joined DESC LIMIT 5) pr ORDER BY name) 6 | UNION ALL 7 | (SELECT name, 2 as filter FROM (SELECT name from it_department ORDER BY date_joined DESC LIMIT 5) it ORDER BY name) 8 | UNION ALL 9 | (SELECT name, 3 as filter FROM (SELECT name from sales_department ORDER BY date_joined DESC LIMIT 5) sales ORDER BY name) 10 | 11 | ) a ORDER BY filter, name; 12 | 13 | 14 | END 15 | -------------------------------------------------------------------------------- /62-checkExpenditure/README.md: -------------------------------------------------------------------------------- 1 |

Check Expenditure

2 |

source: codesignal.com 3 |

Your boss knows that you're a good programmer and that you're responsible, so she's given you a big task - to check the company's expenditure automatically. You're given the table expenditure_plan, which describes all the planned expenditures, and the table allowable_expenditure, which describes the amount that can be spent in certain time periods.

4 |

The expenditure_plan table contains the following columns:

5 | 10 |

The allowable_expenditure table contains the following columns:

11 | 18 |

Your task is to return a table with the columns id and loss, where the value of loss is either 0 (if the expenditure limit with this id was not exceeded) or the amount of money by which the planned expenditure exceeded the allowable expenditure, sorted by id.

19 |

Example

20 |

For given table expenditure_plan

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
monday_dateexpenditure_sum
2016-02-0810
2016-02-1512
2016-06-135
2016-06-2713
43 |

and table allowable_expenditure

44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
idleft_boundright_boundvalue
15830
2232610
64 |

the output should be

65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
idloss
10
28
79 |

In the table expenditure_plan, the Mondays correspond to the weeks with numbers 6, 7, 24, and 26 respectively. For the first time period, we add up 10 and 12 to get 22. Since 22 is smaller than 30, the loss is 0. For the second time period, we add up 5 and 13 to get 18. Since 18 is greater than 10, the allowable expendature for this time period, the answer is 18 - 10 = 8.

80 | 83 |
84 | -------------------------------------------------------------------------------- /62-checkExpenditure/checkExpenditure.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/62-checkExpenditure/checkExpenditure.sql -------------------------------------------------------------------------------- /63-dancingCompetition/README.md: -------------------------------------------------------------------------------- 1 |

Dancing Competition

2 |

source: codesignal.com 3 |

During the dance contest, each judge evaluates the dancers' performances based on three criteria, using a score from 1 to 10 for each of the criteria. You are given a table of the scores awarded to a specific dancer by each judge. Recently, the dance contest made the decision to drop scores awarded by a certain judge if that judge gave an extreme (either minimum or maximum) score for at least two criteria.

4 |

For example, if the judge awarded one of the minimum scores for musicality (i.e., there may be similar scores for musicality, but there may not be smaller scores for that criterion) and one of the maximum scores for floorcraft, all three of the scores given by that judge should not be taken into account.

5 |

Return a table that consists of only the scores that should be considered after this filtering, sorted by arbiter_id.

6 |

The scores table contain the following columns:

7 | 13 |

Example

14 |

For given table scores

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
arbiter_idfirst_criterionsecond_criterionthird_criterion
131010
2234
3567
4259
5222
53 |

the output should be

54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
arbiter_idfirst_criterionsecond_criterionthird_criterion
2234
3567
4259
80 |

The first judge gave the maximal scores for the second and third criteria, so his scores aren't included in the answer. The fifth judge's given scores are all minimal, so her scores aren't included to the answer either.

81 | 84 |
85 | -------------------------------------------------------------------------------- /63-dancingCompetition/dancingCompetition.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/63-dancingCompetition/dancingCompetition.sql -------------------------------------------------------------------------------- /64-trackingSystem/README.md: -------------------------------------------------------------------------------- 1 |

trackingSystem

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /64-trackingSystem/trackingSystem.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/64-trackingSystem/trackingSystem.sql -------------------------------------------------------------------------------- /65-storageOptimization/README.md: -------------------------------------------------------------------------------- 1 |

storageOptimization

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /65-storageOptimization/storageOptimization.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/65-storageOptimization/storageOptimization.sql -------------------------------------------------------------------------------- /66-consecutiveIds/README.md: -------------------------------------------------------------------------------- 1 |

consecutiveIds

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /66-consecutiveIds/consecutiveIds.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/66-consecutiveIds/consecutiveIds.sql -------------------------------------------------------------------------------- /67-holidayEvent/README.md: -------------------------------------------------------------------------------- 1 |

holidayEvent

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /67-holidayEvent/holidayEvent.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/67-holidayEvent/holidayEvent.sql -------------------------------------------------------------------------------- /68-hostnamesOrdering/README.md: -------------------------------------------------------------------------------- 1 |

hostnamesOrdering

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /68-hostnamesOrdering/hostnamesOrdering.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/68-hostnamesOrdering/hostnamesOrdering.sql -------------------------------------------------------------------------------- /69-orderAnalytics/README.md: -------------------------------------------------------------------------------- 1 |

orderAnalytics

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /69-orderAnalytics/orderAnalytics.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/69-orderAnalytics/orderAnalytics.sql -------------------------------------------------------------------------------- /70-customerMessages/README.md: -------------------------------------------------------------------------------- 1 |

customerMessages

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /70-customerMessages/customerMessages.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/70-customerMessages/customerMessages.sql -------------------------------------------------------------------------------- /71-orderPrices/README.md: -------------------------------------------------------------------------------- 1 |

orderPrices

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /71-orderPrices/orderPrices.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/71-orderPrices/orderPrices.sql -------------------------------------------------------------------------------- /72-findTable/README.md: -------------------------------------------------------------------------------- 1 |

findTable

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /72-findTable/findTable.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/72-findTable/findTable.sql -------------------------------------------------------------------------------- /73-queriesExecution/README.md: -------------------------------------------------------------------------------- 1 |

queriesExecution

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /73-queriesExecution/queriesExecution.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/73-queriesExecution/queriesExecution.sql -------------------------------------------------------------------------------- /74-filmLibrary/README.md: -------------------------------------------------------------------------------- 1 |

filmLibrary

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /74-filmLibrary/filmLibrary.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/74-filmLibrary/filmLibrary.sql -------------------------------------------------------------------------------- /75-bugsInComponent/README.md: -------------------------------------------------------------------------------- 1 |

bugsInComponent

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /75-bugsInComponent/bugsInComponent.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/75-bugsInComponent/bugsInComponent.sql -------------------------------------------------------------------------------- /76-freeSeats/README.md: -------------------------------------------------------------------------------- 1 |

freeSeats

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /76-freeSeats/freeSeats.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/76-freeSeats/freeSeats.sql -------------------------------------------------------------------------------- /77-giftPackaging/README.md: -------------------------------------------------------------------------------- 1 |

giftPackaging

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /77-giftPackaging/giftPackaging.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/77-giftPackaging/giftPackaging.sql -------------------------------------------------------------------------------- /78-stringsStatistics/README.md: -------------------------------------------------------------------------------- 1 |

stringsStatistics

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /78-stringsStatistics/stringsStatistics.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/78-stringsStatistics/stringsStatistics.sql -------------------------------------------------------------------------------- /79-unluckyEmployees/README.md: -------------------------------------------------------------------------------- 1 |

unluckyEmployees

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /79-unluckyEmployees/unluckyEmployees.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/79-unluckyEmployees/unluckyEmployees.sql -------------------------------------------------------------------------------- /80-driversInfo/README.md: -------------------------------------------------------------------------------- 1 |

driversInfo

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /80-driversInfo/driversInfo.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/80-driversInfo/driversInfo.sql -------------------------------------------------------------------------------- /81-sortBookChapters/README.md: -------------------------------------------------------------------------------- 1 |

sortBookChapters

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /81-sortBookChapters/sortBookChapters.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/81-sortBookChapters/sortBookChapters.sql -------------------------------------------------------------------------------- /82-typeInheritance/README.md: -------------------------------------------------------------------------------- 1 |

typeInheritance

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /82-typeInheritance/typeInheritance.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/82-typeInheritance/typeInheritance.sql -------------------------------------------------------------------------------- /83-battleshipGameResults/README.md: -------------------------------------------------------------------------------- 1 |

battleshipGameResults

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /83-battleshipGameResults/battleshipGameResults.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/83-battleshipGameResults/battleshipGameResults.sql -------------------------------------------------------------------------------- /84-tictactoeTournament/README.md: -------------------------------------------------------------------------------- 1 |

tictactoeTournament

2 |

source: codesignal.com 3 | 4 | -------------------------------------------------------------------------------- /84-tictactoeTournament/tictactoeTournament.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waq-r/CodeSignal-Databases/86ed893c93dccd8f954f696978302acd4c56e51e/84-tictactoeTournament/tictactoeTournament.sql --------------------------------------------------------------------------------