본문 바로가기

SQL

[mysql] Subbranch, group by, having, rollup

Subbranch

select Name, Population, CountryCode
from city
where CountryCode = (select CountryCode
from city
where Name = 'Chicago');

 

 

 

 

 

 

Group by

select Name, avg(Population)
from country
group by Name;

 

Having

select max(Population) as max, Min(Population) as min
from city
having max > 10000000;

 

Rollup

select CountryCode, Name, sum(Population)
from city
group by CountryCode, Name with rollup;

 

'SQL' 카테고리의 다른 글

[mysql] concat, substring, if, case, case + if  (0) 2020.07.15
[mysql] join, union  (0) 2020.06.27
SQL  (0) 2020.06.17