1 2 3 4 5 6 7 8 9 10 11 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 42 43 44 45 46 47
|
create table user ( user_id int primary key auto_increment, name varchar(20) default null ); create table addr ( addr_id int primary key auto_increment, addr varchar(20), user_id int ); insert into user(name) values ("jin"), ("po"), ("alice"); select * from user; insert into addr(addr, user_id) values ("seoul", 1), ("busan", 2), ("daegu", 4), ("seoul", 5); select * from addr;
select user.user_id, user.name, addr.addr from user join addr on user.user_id = addr.user_id; select * from user join addr;
select user.user_id, user.name, addr.addr from user left join addr on user.user_id = addr.user_id; select addr.user_id, user.name, addr.addr from addr left join user on user.user_id = addr.user_id;
select user.user_id, user.name, addr.addr from user right join addr on user.user_id = addr.user_id; select user.user_id, user.name, addr.addr from addr right join user on user.user_id = addr.user_id;
use world; select code, city.name as city_name, country.name as country_name, country.population as country_pop, city.population as city_pop, round(city.Population/country.population * 100, 2) as rate from country join city on country.code = city.CountryCode having rate >= 20 order by rate desc;
select country.name, countrylanguage.language, round(country.population * countrylanguage.percentage * 0.01) as lp from country join countrylanguage on country.code = countrylanguage.CountryCode;
select country.name, countrylanguage.language, round(country.population * countrylanguage.percentage * 0.01) as lp from country, countrylanguage where country.code = countrylanguage.CountryCode;
select distinct(country.continent), count(countrylanguage.language) from country join countrylanguage on country.code = countrylanguage.CountryCode group by continent;
|