๋ฐ์ํ
Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- ํ์ ๋ณ์
- ์์ด
- ํฉํ ๋ฆฌ์ผ ์ง๋ฒ
- ์ง ๊ฐ ์์ธก ๋ถ์
- ๋ค์ต์คํธ๋ผ ์๊ณ ๋ฆฌ์ฆ
- ์ด๊ฒ์ด ์ทจ์ ์ ์ํ ์ฝ๋ฉํ ์คํธ๋ค
- ์๋ฐ
- DFS
- ์ด์ง์ ๋ณํ
- sql
- ํ๋ก๊ทธ๋๋จธ์ค
- MacOS
- ์ ํ ํฌ ํ์ด์ฌ
- java
- Extended Slices
- jdbc
- BFS
- dacon
- ์ต์
- ๋ฐ์ค๊ทธ๋ํ
- np.zeros_like
- 2BPerfect
- matplotlib
- Do_it
- Do it
- ๋ฐฑ์ค
- PYTHON
- mysql
- ๋ธ๋ผ์ฐ์ ์คํ
- ์ฐธ์กฐ ๋ณ์
Archives
- Today
- Total
๐ฆ ๊ณต๋ฃก์ด ๋์!
SQL ๋ณธ๋ฌธ
Select ์ปฌ๋ผ from ์คํค๋ง.ํ
์ด๋ธ
where population between 1000000 and 2000000
์ซ์ ์ฐ์ฐ์
= '! = ' <> > <
- null ๊ฐ์ =๋ก ์ธ์์ด ๋ถ๊ฐํ๊ณ is null๋ก ํด์ค์ผํจ
- ์์
select*from world.country
where inDepyear is null;
๋ฌธ์์ฐ์ฐ์
select count(*)from city where name LIKE'___'
select count(*)from city where name LIKE'%m'
- %๋ ์์ ๋ฌธ์๊ฐ ์ ํ์์ด _๋ ํ ๊ฐ
์๋ธ์ฟผ๋ฆฌ
select *
from city
where population>(select population from city where name ='Seoul');
select *
from city
where population > ANY ( select *
from city
where CountryCode ='Kor');
- ANY ์ ์๋ธ ์ฟผ๋ฆฌ ๊ฐ์ ์ ์ผ ์์ ๊ฐ๋ณด๋ค ์ปค์ผํจ
select name
from city
where Population =(select avg(population)
from city);
- foreign key
- ํ์ ๋ ๋์ผํด์ผํ๋ค
- distinct ์ค๋ณต์ ์ธ
select distinct CountryCode
from city;
select count(countrycode)/count(distinct countrycode)
from city;
- count ๋ด๋ถ์ ์์ฑ์ ํด์ผ ์ค๋ณต์ด ์๋๋ค.
- group by
select countrycode, count(name),sum(population)
from city
group by countrycode;
select countrycode, count(name),sum(population)
from city
group by countrycode;
- ๋ณด์ฌ์ค ๊ฒ๋ค์ select๋ก ์ ์ group by๋ ๊ธฐ์ค์ด ๋ ๊ฒ ์ ์
- group by๋ where์ ๋ชป์ ๋์ having ์ ์ ์ด๋ค
- having ์
select countrycode as '๊ตญ๊ฐ์ฝ๋',
count(name) as '๋ฑ๋ก๋์์',
sum(population) as '์ด์ธ๊ตฌ์',
avg(population) as 'ํ๊ท ์ธ๊ตฌ์',
district
from city
group by CountryCode
Having Sum(population)>1000000
order by count(name) DESC,sum(population);
- ๋ฌด์กฐ๊ฑด group by ์ ๋ค์ ๋์์ผํ๋ค.
- order by
select countrycode as '๊ตญ๊ฐ์ฝ๋',
count(name) as '๋ฑ๋ก๋์์',
sum(population) as '์ด์ธ๊ตฌ์',
avg(population) as 'ํ๊ท ์ธ๊ตฌ์'
from city
group by CountryCode
order by count(name),sum(popualation);
-- DESC(๋ด๋ฆผ์ฐจ์)
- ์ ๋ ฌ ๊ธฐ์ค
- ์คํํ๋ ๋ช ๋ น์ด?
-
count(*) sum() avg() min() max() AS
์ฐ์ ์ด๋ฏธ์ง๋ฅผ ๋ณด๊ณ ํ๋ฉด ์ดํด๊ฐ ์ฝ๋ค.
- Join
select*from sales
INNER JOIN member
on sales.mem_id = member.id;
select sales.*,member.name,member.addr from sales
inner join member
on sales.mem_id = member.id;
- inner join ์ฐ๊ฒฐ(๊ต์งํฉ)
select distinct actor.first_name
from film_actor
inner join actor
on film_actor.actor_id=actor.actor_id;
select distinct film.title
from film_actor
inner join film
on film_actor.film_id=film.film_id;
select film.title,actor.first_name
from film_actor
inner join film
on film_actor.film_id=film.film_id
inner join actor
on film_actor.actor_id=actor.actor_id;
- outer join
SELECT * FROM hellodb.sales;
select member.*, sales.*
from member
left outer join sales
on member.id = sales.mem_id;
select film.*
from film_actor
right outer join film
on film.film_id=film_actor.film_id
where film_actor.actor_id is null;
๋ฐ์ํ
'Data > Database_MySQL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
SQL...2 (0) | 2021.12.13 |
---|---|
MacOS MySQL ์ค์น (0) | 2021.12.09 |
Comments