DROP DATABASE IF EXISTS pokemon; CREATE DATABASE pokemon; USE pokemon; CREATE TABLE mypokemon( number int, name varchar(20), type varchar(20), height float, weight float, attack float, defense float, speed int ); INSERT INTO mypokemon(number, name, type) VALUES (10,'caterpie', 'bug'), (25,'picachu','electric'), (27,'raichu','electric'), (133,'eevee','normal'), (152,'chikoirita','grass'); CREATE TABLE ability( number int, height float, weight float, attack float, defense float, speed int ); INSERT INTO mypokemon(number, height, weight, attack, defense, speed) VALUES (10,0.3,2.9,.30,35,45), (25,0.4,6,55,40,90), (27,0.8,30,90,55,110), (133,0.3,6.5,55,50,55), (152,0.9,6.4,49,65,45), (153,1.2,15.8,62,80,60), (172,0.3,2,40,15,60), (470,1,25.5,110,130,95);
SELECT name, attack, defense FROM mypokemon LEFT JOIN ability ON mypokemon.number = ability.numer;
SELECT ability.number, name FROM mypokemon RIGHT JOIN ability ON mypokemon.number = ability.number;
SELECT type, AVG(height) FROM mypokemon LEFT JOIN ability ON mypokemon.number = ability.number GROUP BY type;
SELECT type, AVG(weight) FROM mypokemon LEFT JOIN ability ON mypokemon.number = ability.number GROUP BY type;
SELECT type, AVG(height), AVG(weight) FROM mypokemon LEFT JOIN ability ON mypokemon.number = ability.number GROUP BY type;
SELECT mypokemon.number, name, attack, defense FROM mypokemon LEFT JOIN ability ON mypokemon.number = ability.number WHERE mypokemon.number >= 100;
SELECT name FROM mypokemon LEFT JOIN ability ON mypokemon.number = ability.number ORDER BY attack + defense DESC;
SELECT name FROM mypokemon LEFT JOIN ability ON mypokemon.number = ability.number ORDER BY speed DESC LIMIT 1;