
| Function | Description |
|---|---|
| COUNT | ์ด ๊ฐฏ์๋ฅผ ๊ณ์ฐํด์ฃผ๋ ํจ์ |
| SUM | ํฉ๊ณ๋ฅผ ๊ณ์ฐํด์ฃผ๋ ํจ์ |
| AVG | ํ๊ท ์ ๊ณ์ฐํด์ฃผ๋ ํจ์ |
| MIN | ๊ฐ์ฅ ์์ ๊ฐ์ ์ฐพ์์ฃผ๋ ํจ์ |
| MAX | ๊ฐ์ฅ ํฐ ๊ฐ์ ์ฐพ์์ฃผ๋ ํจ์ |
| FIRST | ์ฒซ๋ฒ์งธ ๊ฐ์ ๋ฆฌํดํด์ฃผ๋ ํจ์ |
| LAST | ๋ง์ง๋ง ๊ฐ์ ๋ฆฌํดํด์ฃผ๋ ํจ์ |
๊ทธ๋ฃนํํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์กฐํ
์กฐ๊ฑด์ ์ง๊ณํจ์ ๊ฐ ํฌํจ๋๋ ๊ฒฝ์ฐ WHERE ๋์ HAVING ์ฌ์ฉ
COUNT ๋ฌธ๋ฒ
select count(column) from tablename
where condition
SUM ๋ฌธ๋ฒ
select sum(column) from tablename
where condition
AVG ๋ฌธ๋ฒ
select avg(column) from tablename
where condition
MIN ๋ฌธ๋ฒ
select min(column) from tablename
where condition
MAX ๋ฌธ๋ฒ
select max(column) from tablename
where condition
GROUP BY ๋ฌธ๋ฒ
select column1, column2, ...
from table
where condition
group by column1, column2, ...
HAVING ๋ฌธ๋ฒ
select column1, column2, ...
from tablename
where condition
group by column1, column2, ...
having condition //์ง๊ณํจ์ ํฌํจ
group by column1, column2, ...
- ๊ณต๊ณต๋ฐ์ดํฐ csv ํ์ผ๋ก ์ฐ์ตํ๊ธฐ
์์ธ์ ๊ณต๊ณต์์ ๊ฑฐ ๋์ฌ์๋ณ ์ด์ฉ์ ๋ณด(์๋ณ)- ํ๋ค์ค๋ก ๋ฐ์ดํฐ ์ดํด๋ณด๊ธฐ
+ ๋ฐ์ดํฐ insert 80๋ถ ์์(์ฐธ๊ณ ํ์ธ์!)
โ๏ธcsv ํ์ผ ์ธ์ฝ๋ฉ ์์๋ณด๋ ๋ฐฉ๋ฒ
import chardet
filename = "์์ธํน๋ณ์ ๊ณต๊ณต์์ ๊ฑฐ ๋์ฌ์๋ณ ์ด์ฉ์ ๋ณด(์๋ณ).csv" # ํ์ผ๋ช
with open(filename,'rb')as f:
result = chardet.detect(f.readline())
print(result['encoding'])
select ์์น๊ตฌ, max(๋์ฌ๊ฑด์) max from ๊ณต๊ณต์์ ๊ฑฐ
group by ์์น๊ตฌ
order by max(๋์ฌ๊ฑด์) desc
limit 5;
select ์์น๊ตฌ, min(๋์ฌ๊ฑด์) min from ๊ณต๊ณต์์ ๊ฑฐ
group by ์์น๊ตฌ
order by min(๋์ฌ๊ฑด์)
limit 5;
select ์์น๊ตฌ, truncate(avg(๋์ฌ๊ฑด์),-1) avg from ๊ณต๊ณต์์ ๊ฑฐ
group by ์์น๊ตฌ
order by avg(๋์ฌ๊ฑด์) desc
limit 5;
select ์์น๊ตฌ, truncate(avg(๋์ฌ๊ฑด์),-1) avg from ๊ณต๊ณต์์ ๊ฑฐ
where ์์น๊ตฌ like '____'
group by ์์น๊ตฌ
having avg(๋์ฌ๊ฑด์) >=1500;
์คํํ์ธ
![]() | ![]() | ![]() | ![]() |
|---|