text SQL挑战5
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text SQL挑战5相关的知识,希望对你有一定的参考价值。
ysql> CREATE TABLE player
-> (id INT, wizard_id INT, team_id INT, role VARCHAR(50), enrollment_date DATE);
Query OK, 0 rows affected (0,07 sec)
mysql> describe player;
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| wizard_id | int(11) | YES | | NULL | |
| team_id | int(11) | YES | | NULL | |
| role | varchar(50) | YES | | NULL | |
| enrollment_date | date | YES | | NULL | |
+-----------------+-------------+------+-----+---------+-------+
5 rows in set (0,00 sec)
mysql> CREATE TABLE team (id INT, name varchar(80));
Query OK, 0 rows affected (0,07 sec)
mysql> describe wizard;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| firstname | varchar(100) | NO | | NULL | |
| lastname | varchar(100) | NO | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
3 rows in set (0,00 sec)
mysql> describe team;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(80) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0,00 sec)
mysql>
SELECT team.name AS name, player.role AS role, wizard.lastname AS lastname, wizard.firstname AS firstname FROM player JOIN wizard ON player.wizard_id=wizard.id JOIN team ON player.team_id=team.id ORDER BY name, role, lastname, firstname ASC;
+------------+--------+-----------------+-------------+
| name | role | lastname | firstname |
+------------+--------+-----------------+-------------+
| Gryffindor | beater | Black | Sirius |
| Gryffindor | beater | Brown | Lavender |
| Gryffindor | beater | Finnigan | Seamus |
| Gryffindor | beater | Hagrid | Rubeus |
| Gryffindor | beater | Longbottom | Alice |
| Gryffindor | beater | McGonagall | Minerva |
| Gryffindor | beater | Potter | Harry |
| Gryffindor | beater | Potter | James |
| Gryffindor | beater | Thomas | Dean |
| Gryffindor | beater | Weasley | Arthur |
| Gryffindor | beater | Weasley | Percy |
| Gryffindor | chaser | Bell | Katie |
| Gryffindor | chaser | Dumbledore | Albus |
| Gryffindor | chaser | Granger | Hermione |
| Gryffindor | chaser | J. | Lily |
| Gryffindor | chaser | Jordan | Lee |
| Gryffindor | chaser | Longbottom | Augusta |
| Gryffindor | chaser | Longbottom | Frank |
| Gryffindor | chaser | Longbottom | Neville |
| Gryffindor | chaser | Pettigrew | Peter |
| Gryffindor | chaser | Spinnet | Alicia |
| Gryffindor | chaser | Weasley | George |
| Gryffindor | chaser | Wood | Oliver |
| Gryffindor | keeper | | Cadogan |
| Gryffindor | keeper | Creevey | Dennis |
| Gryffindor | keeper | de | Nicholas |
| Gryffindor | keeper | Dumbledore | Aberforth |
| Gryffindor | keeper | Johnson | Angelina |
| Gryffindor | keeper | Weasley | Ginevra |
| Gryffindor | seeker | Binns | Cuthbert |
| Gryffindor | seeker | Creevey | Colin |
| Gryffindor | seeker | Gryffindor | Godric |
| Gryffindor | seeker | Vane | Romilda |
| Gryffindor | seeker | Weasley | Fred |
| Gryffindor | seeker | Weasley | Ronald |
| Gryffindor | seeker | Weasley | William |
| Hufflepuff | beater | Abbott | Hannah |
| Hufflepuff | beater | Finch-Fletchley | Justin |
| Hufflepuff | beater | Friar | Fat |
| Hufflepuff | beater | Smith | Hepzibah |
| Hufflepuff | beater | Sprout | Pomona |
| Hufflepuff | beater | Tonks | Nymphadora |
| Hufflepuff | chaser | Bones | Amelia |
| Hufflepuff | chaser | Scamander | Newton |
| Hufflepuff | keeper | Bones | Susan |
| Hufflepuff | keeper | Diggory | Cedric |
| Hufflepuff | keeper | Smith | Zacharias |
| Hufflepuff | seeker | Hufflepuff | Helga |
| Ravenclaw | beater | Clearwater | Penelope |
| Ravenclaw | beater | Quirrell | Quirinus |
| Ravenclaw | beater | Ravenclaw | Helena |
| Ravenclaw | beater | Warren | Myrtle |
| Ravenclaw | chaser | Chang | Cho |
| Ravenclaw | chaser | Edgecombe | Marietta |
| Ravenclaw | chaser | Flitwick | Filius |
| Ravenclaw | chaser | Goldstein | Anthony |
| Ravenclaw | chaser | Lockhart | Gilderoy |
| Ravenclaw | chaser | Lovegood | Luna |
| Ravenclaw | chaser | Lovegood | Xenophilius |
| Ravenclaw | chaser | Ollivander | Garrick |
| Ravenclaw | seeker | Corner | Michael |
| Ravenclaw | seeker | Ravenclaw | Rowena |
| Ravenclaw | seeker | Trelawney | Sybill |
| Slytherin | beater | Bulstrode | Millicent |
| Slytherin | beater | Crabbe | Vincent |
| Slytherin | beater | Flint | Marcus |
| Slytherin | beater | Parkinson | Pansy |
| Slytherin | beater | Snape | Severus |
| Slytherin | beater | Zabini | Blaise |
| Slytherin | chaser | Baron | Bloody |
| Slytherin | chaser | Lestrange | Bellatrix |
| Slytherin | chaser | Lestrange | Rodolphus |
| Slytherin | chaser | Malfoy | Draco |
| Slytherin | chaser | Malfoy | Lucius |
| Slytherin | chaser | Nigellus | Phineas |
| Slytherin | chaser | Nott | Theodore |
| Slytherin | chaser | Riddle | Tom |
| Slytherin | chaser | Tonks | Andromeda |
| Slytherin | keeper | Black | Regulus |
| Slytherin | seeker | Goyle | Gregory |
| Slytherin | seeker | Lestrange | Rabastan |
| Slytherin | seeker | Malfoy | Narcissa |
| Slytherin | seeker | Slytherin | Salazar |
| Slytherin | seeker | Umbridge | Dolores |
+------------+--------+-----------------+-------------+
84 rows in set (0,00 sec)
SELECT wizard.firstname as firstname, wizard.lastname as lastname FROM player JOIN wizard ON player.wizard_id=wizard.id WHERE role = 'seeker' ORDER BY firstname, lastname ASC;
+-----------+------------+
| firstname | lastname |
+-----------+------------+
| Colin | Creevey |
| Cuthbert | Binns |
| Dolores | Umbridge |
| Fred | Weasley |
| Godric | Gryffindor |
| Gregory | Goyle |
| Helga | Hufflepuff |
| Michael | Corner |
| Narcissa | Malfoy |
| Rabastan | Lestrange |
| Romilda | Vane |
| Ronald | Weasley |
| Rowena | Ravenclaw |
| Salazar | Slytherin |
| Sybill | Trelawney |
| William | Weasley |
+-----------+------------+
16 rows in set (0,00 sec)
SELECT firstname, lastname FROM wizard WHERE id NOT IN (SELECT wizard_id FROM player);
+-----------+----------+
| firstname | lastname |
+-----------+----------+
| Terry | Boot |
| Crabbe | |
| Remus | Lupin |
| Padma | Patil |
| Parvati | Patil |
| Demelza | Robins |
| Horace | Slughorn |
| Charles | Weasley |
| Molly | Weasley |
+-----------+----------+
9 rows in set (0,00 sec)
以上是关于text SQL挑战5的主要内容,如果未能解决你的问题,请参考以下文章