MySQL
sum , count , average
소힌
2022. 1. 27. 16:38
-- 집계함수 어떠한 덩어리에 대해서 전체적인 연산을 해주는 함수
-- 합 , 평균 , 개수 ...
-- 합
select sum(population) from country;
select count(*) from country;
-- 평균
select sum(population)/count(*) as 평균 from country;
select avg(population) from country;
-- 최대값
select max(population) from country;
-- 최소값
select min(population) from country;
-- region이 ~~ america로 끝나는 국가의 개수
select count(*) as '아메리카 국가 개수' from country where region like "%america";
-- continent 가 asia 인 국가의평균 gnp
select round(avg(gnp),1) as "아시아 평균 gnp" from country where continent = "asia";
-- continent의 개수
select count(distinct Continent) from country;