Skip to content

Instantly share code, notes, and snippets.

@AlenaNik
Created May 17, 2019 09:12
Show Gist options
  • Save AlenaNik/c33dd3a7e7c191cca9a81d3f00acf081 to your computer and use it in GitHub Desktop.
Save AlenaNik/c33dd3a7e7c191cca9a81d3f00acf081 to your computer and use it in GitHub Desktop.
MySQL Exercise
1) SELECT * FROM wild.wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-01-01';
Result:
[
{
"id" : 1,
"firstname" : "harry",
"lastname" : "potter",
"birthday" : "1980-07-31",
"birth_place" : "london",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 2,
"firstname" : "hermione",
"lastname" : "granger",
"birthday" : "1979-09-19",
"birth_place" : "",
"biography" : "Friend of Harry Potter",
"is_muggle" : 0
},
{
"id" : 4,
"firstname" : "ron",
"lastname" : "weasley",
"birthday" : "1980-03-01",
"birth_place" : "",
"biography" : "Best friend of Harry",
"is_muggle" : 0
},
{
"id" : 5,
"firstname" : "ginny",
"lastname" : "weasley",
"birthday" : "1981-08-11",
"birth_place" : "",
"biography" : "Sister of Ron and girlfriend of Harry",
"is_muggle" : 0
},
{
"id" : 6,
"firstname" : "fred",
"lastname" : "weasley",
"birthday" : "1978-04-01",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 7,
"firstname" : "george",
"lastname" : "weasley",
"birthday" : "1978-04-01",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 10,
"firstname" : "drago",
"lastname" : "malefoy",
"birthday" : "1980-06-05",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 14,
"firstname" : "dudley",
"lastname" : "dursley",
"birthday" : "1980-06-23",
"birth_place" : "",
"biography" : "Cousin d'Harry",
"is_muggle" : 1
},
{
"id" : 15,
"firstname" : "harry",
"lastname" : "potter",
"birthday" : "1980-07-31",
"birth_place" : "london",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 16,
"firstname" : "hermione",
"lastname" : "granger",
"birthday" : "1979-09-19",
"birth_place" : "",
"biography" : "Friend of Harry Potter",
"is_muggle" : 0
},
{
"id" : 18,
"firstname" : "ron",
"lastname" : "weasley",
"birthday" : "1980-03-01",
"birth_place" : "",
"biography" : "Best friend of Harry",
"is_muggle" : 0
},
{
"id" : 19,
"firstname" : "ginny",
"lastname" : "weasley",
"birthday" : "1981-08-11",
"birth_place" : "",
"biography" : "Sister of Ron and girlfriend of Harry",
"is_muggle" : 0
},
{
"id" : 20,
"firstname" : "fred",
"lastname" : "weasley",
"birthday" : "1978-04-01",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 21,
"firstname" : "george",
"lastname" : "weasley",
"birthday" : "1978-04-01",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 24,
"firstname" : "drago",
"lastname" : "malefoy",
"birthday" : "1980-06-05",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 28,
"firstname" : "dudley",
"lastname" : "dursley",
"birthday" : "1980-06-23",
"birth_place" : "",
"biography" : "Cousin d'Harry",
"is_muggle" : 1
},
{
"id" : 29,
"firstname" : "harry",
"lastname" : "potter",
"birthday" : "1980-07-31",
"birth_place" : "london",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 30,
"firstname" : "hermione",
"lastname" : "granger",
"birthday" : "1979-09-19",
"birth_place" : "",
"biography" : "Friend of Harry Potter",
"is_muggle" : 0
},
{
"id" : 32,
"firstname" : "ron",
"lastname" : "weasley",
"birthday" : "1980-03-01",
"birth_place" : "",
"biography" : "Best friend of Harry",
"is_muggle" : 0
},
{
"id" : 33,
"firstname" : "ginny",
"lastname" : "weasley",
"birthday" : "1981-08-11",
"birth_place" : "",
"biography" : "Sister of Ron and girlfriend of Harry",
"is_muggle" : 0
},
{
"id" : 34,
"firstname" : "fred",
"lastname" : "weasley",
"birthday" : "1978-04-01",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 35,
"firstname" : "george",
"lastname" : "weasley",
"birthday" : "1978-04-01",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 38,
"firstname" : "drago",
"lastname" : "malefoy",
"birthday" : "1980-06-05",
"birth_place" : "",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 42,
"firstname" : "dudley",
"lastname" : "dursley",
"birthday" : "1980-06-23",
"birth_place" : "",
"biography" : "Cousin d'Harry",
"is_muggle" : 1
}
]
2)
SELECT * FROM wizard WHERE firstname LIKE 'H%'
{
"id" : 1,
"firstname" : "harry",
"lastname" : "potter",
"birthday" : "1980-07-31",
"birth_place" : "london",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 2,
"firstname" : "hermione",
"lastname" : "granger",
"birthday" : "1979-09-19",
"birth_place" : "",
"biography" : "Friend of Harry Potter",
"is_muggle" : 0
},
{
"id" : 15,
"firstname" : "harry",
"lastname" : "potter",
"birthday" : "1980-07-31",
"birth_place" : "london",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 16,
"firstname" : "hermione",
"lastname" : "granger",
"birthday" : "1979-09-19",
"birth_place" : "",
"biography" : "Friend of Harry Potter",
"is_muggle" : 0
},
{
"id" : 29,
"firstname" : "harry",
"lastname" : "potter",
"birthday" : "1980-07-31",
"birth_place" : "london",
"biography" : "",
"is_muggle" : 0
},
{
"id" : 30,
"firstname" : "hermione",
"lastname" : "granger",
"birthday" : "1979-09-19",
"birth_place" : "",
"biography" : "Friend of Harry Potter",
"is_muggle" : 0
}
]
3) SELECT firstname, lastname FROM wild.wizard WHERE lastname='potter' order by firstname;
[
{
"firstname" : "harry",
"lastname" : "potter"
},
{
"firstname" : "harry",
"lastname" : "potter"
},
{
"firstname" : "harry",
"lastname" : "potter"
},
{
"firstname" : "lily",
"lastname" : "potter"
},
{
"firstname" : "lily",
"lastname" : "potter"
},
{
"firstname" : "lily",
"lastname" : "potter"
}
]
4) SELECT lastname, firstname, birthday FROM wild.wizard order by birthday Asc LIMIT 1
[
{
"lastname" : "dumbledore",
"firstname" : "albus",
"birthday" : "1881-07-01"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment