본문 바로가기
Interests/Data & Programming

Daily SQL Practice 1 (SQLZOO)

by Melissa Levasseur 2023. 4. 12.

매일 아침 SQL 문제 한개씩 풀어 제끼기를 위해 복기 작업을 시작...!

다행히 기본을 위한 practice materials 들이 꽤 있음. (참고 링크 : https://idatau.tistory.com/274)

이번주는 기본 단계로 SQLZOO라는 사이트의 예제와 퀴즈를 뿌실 예정!! (최대 1시간정도를 목표로 하기 때문에 너무 과하면 흥미를 잃을 수 있음 ㅋㅋㅋ)

오늘 학습한 내용

기억해 둘만한 내용

1. 한번에 묶어서 가져오기

SELECT name, population 
from world
where name in('France', 'Germany', 'Italy')

2. select에서 바로 계산 가능

SELECT name, population/area
FROM world
WHERE name IN ('China', 'Nigeria', 'France', 'Australia')

3. 글자 길이 (len으로 쓰기도 함)

SELECT name,length(name)
FROM world
WHERE length(name)=5 and region='Europe'

4. 앞/뒤 글자 기준 필터링 (LIKE , "text%)

SELECT name, population
FROM world
WHERE name LIKE "Al%" or LIKE “zb%”

5. 범위 설정 (Between 활용)

SELECT name, population
FROM world
WHERE population BETWEEN 1000000 AND 1250000

** 꼭 보여지는 값(select~)이 where 절에서 활용되는 값일 필요는 없다! 전체 DB를 활용한다는 전제라면 (from~)

6. 배타적 OR(XOR) (NOT 활용)

select name, population, area
from world
where (population > 250000000 AND (NOT area > 3000000)) or ((NOT population > 250000000) AND area > 3000000)

7. 반올림 (Round, 자리수)

select name, Round(population/1000000,2),Round(gdp/1000000000,2)
from world
where continent = 'South America'

8. text 첫글자 (left, 몇번째) / 같지 않음 (<>)

SELECT name, capital
FROM world
where left(name,1)=left(capital,1)
and name<>capital

9. 

'Interests > Data & Programming' 카테고리의 다른 글

MidJourney 전시회 준비  (0) 2023.07.08
2021 머신러닝 야학 - The end  (0) 2021.01.19
2021 머신러닝야학 - 8  (0) 2021.01.18
2021 머신러닝야학 - 7  (0) 2021.01.18
2021 머신러닝야학 - 6  (0) 2021.01.17

댓글