-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sol #18
Open
ilovepinkpony1
wants to merge
1
commit into
mate-academy:master
Choose a base branch
from
ilovepinkpony1:vitalii_o
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
sol #18
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,133 +16,141 @@ Here are eight famous people: | |
1. Using your favorite DB client, design and create a database table called `people` that would store the information presented above (create a database first if you don’t have any existing ones to play with). Don’t bother with creating any keys or indices for now, just create the five columns. Copy and paste the SQL query generated by the client below (it should start with `create table` or something similar; if it is difficult to find the query generated by your client, ask for assistance): | ||
|
||
```postgresql | ||
CREATE TABLE ... | ||
CREATE TABLE famouse_peoples (id INTEGER, first_name TEXT, last_name TEXT, birth_year INTEGER, deth_year INTEGER); | ||
``` | ||
|
||
2. **Manually** create a query or a series of queries that would fill the table with the information above. Put the query/queries below: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
INSERT INTO famouse_peoples (id, first_name, last_name, birth_year, deth_year) | ||
VALUES (1, 'Marilyn', 'Monroe', 1926, 1962), | ||
(2, 'Abraham', 'Lincoln', 1809, 1865), | ||
(3, 'Nelson', 'Mandela', 1918, 2013), | ||
(4, 'Winston', 'Churchill', 1874, 1965), | ||
(5, 'Bill', 'Gates', 1955, NULL), | ||
(6, 'Charles', 'Darwin', 1809, 1882), | ||
(7, 'Pele', NULL, 1940, NULL), | ||
(8, 'Fidel', 'Castro', 1926, NULL); | ||
``` | ||
|
||
3. Create a query that would return everything from the table: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples; | ||
``` | ||
|
||
4. Create a query that would return a single row: the person with the ID of 5. | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples WHERE id = 5; | ||
``` | ||
|
||
5. Create a query that would return the four people with the following IDs: 1, 3, 7, 8. | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples WHERE id IN (1, 3, 7, 8); | ||
``` | ||
|
||
6. Create a query that would return all the people except the person with the ID of 4 (`Winston Churchill`). | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples WHERE id != 4; | ||
``` | ||
|
||
7. Create a query that would select the first names and last names of the people who were born after 1920: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT first_name, last_name FROM famouse_peoples WHERE birth_year > 1920; | ||
``` | ||
|
||
8. Create a query that would select the IDs of the living people: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT id FROM famouse_peoples WHERE deth_year ISNULL; | ||
``` | ||
|
||
9. Create a query that would return the years of birth and the years of death of everyone who has died. The columns should be aliased `b` and `d` respectively. | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT birth_year AS b, deth_year AS d FROM famouse_peoples WHERE deth_year IS NOT NULL; | ||
``` | ||
|
||
10. Create a query that would return the list of all years of birth, without repetition: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT DISTINCT year_of_birth FROM famouse_peoples; | ||
``` | ||
|
||
11. Create a query that would select the people with either their first or last name starting with an `M`: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples WHERE first_name LIKE 'M%' OR last_name LIKE 'M%'; | ||
``` | ||
|
||
12. Create a query that would select the people with both their first and last name starting with an `M`: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples WHERE first_name LIKE 'M%' AND last_name LIKE 'M%'; | ||
``` | ||
|
||
13. Create a query that would select all the people except those whose last name starts with a `C`: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples WHERE last_name NOT LIKE 'C%'; | ||
``` | ||
|
||
14. Create a query that would select the people whose first name starts with a letter that precedes `M` in the English alphabet: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples WHERE first_name ~ '[A-L]'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SELECT * FROM famouse_peoples WHERE first_name ~ '^[A-L]'; |
||
``` | ||
|
||
15. Create a query that would return all the people sorted by their last name alphabetically: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT * FROM famouse_peoples ORDER BY last_name; | ||
``` | ||
|
||
16. Create a query that would return the first names of the people sorted in the reverse alphabetical order. The column should be aliased `fn`. | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT first_name AS fn FROM famouse_peoples ORDER BY birth_year DESC; | ||
``` | ||
|
||
17. Create a query that would return the people sorted by their year of birth in the descending order, and then (if two or more people share the same year of birth) by their last name alphabetically: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
SELECT first_name FROM famouse_peoples ORDER BY birth_year DESC, last_name; | ||
``` | ||
|
||
18. Set everyone’s last name to your last name: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
UPDATE famouse_peoples SET last_name = 'Oliinik'; | ||
``` | ||
|
||
19. Update the first name of everyone who was born before 1900 to your favorite character’s name: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
UPDATE famouse_peoples SET first_name = 'Batman' WHERE birth_year < 1900; | ||
``` | ||
|
||
20. Add 1 to both the year of birth and year of death for everyone whose ID is less than 5: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
UPDATE famouse_peoples SET birth_year = birth_year + 1, deth_year = deth_year + 1 WHERE id < 5; | ||
``` | ||
|
||
21. Delete from the table everyone who died before 2000: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
DELETE FROM famouse_peoples WHERE deth_year < 2000; | ||
``` | ||
|
||
22. Delete everyone from the table: | ||
|
||
```postgresql | ||
... here goes your SQL ... | ||
DELETE FROM famouse_peoples; | ||
``` | ||
|
||
Don’t forget to create a pull request. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ISNULL - функція, а тут тобі потрібен IS NULL