본문 바로가기

내일배움캠프

내일배움캠프 사전캠프 TIL/2일차 SQL 걷기반 진행!

오늘의 목표!

- 사전캠프 걷기반 마무리 해보기

 

-  걷기반 진행

 

3단계

 

9. select customer_id from orders where amount >= 2;

10. select product_id from orders where amount >= 2 and order_Date > '2023-11-02'

11. select product_id from orders where amount < 3 and shipping_free > 15000;

12. select shipping_free from orders order by shipping_free desc;

 

3단계에서 배울 수 있는건

 

1. 논리연산자

 

두 개의 조건을 만족하면  조건식이 성립하는 and  두 조건 중 한 개라도 만족하면 조건식이 성립하는 or를 사용하면 됩니다

 

2. order by 

 

기본값은(ASC) 오름차순이며 DESC 내림차순도 존재합니다.

 

 

4단계

 

13. select name,track from sparta_students;

14. select name from sparta_students where track != 'Unity';

15. select name from sparta_students where enrollment_year = 2023 or enrollment_year = 2021;

16. select enrollment_year from sparta_students where track = 'Node.js' and grade = 'A';

 

4단계에서 배울 수 있는건

 

1.비교연산자

 

5단계

17. select name from team_projects where aws_cost >= 40000;

18. select name from team_projects where date_format(start_date,'%Y') = '2022';

19. select name from team_projects where end_date > now();

20. select  datediff(end_date , start_date) from team_projects;

 

5단계에서 배울 수 있는건

 

1. (DATE_FORMAT)

    원하는 형식으로 날짜 데이터를 뽑아서 활용 가능합니다

 

2. NOW()

https://mooonstar.tistory.com/entry/MYSQLNOW-SYSDATE%EC%9D%98-%EC%B0%A8%EC%9D%B4

 

[MYSQL]NOW(), SYSDATE()의 차이

NOW(), SYSDATE()의 차이 MySQL에서 현재 시각의 데이터를 가져올 수 있는 몇 가지의 방법이 있다. 하지만 특정 기준 없이 무분별하게 사용되는 경우가 있어 차이를 알아보고자 한다. NOW() MySQL 서버의

mooonstar.tistory.com

 

now() 말고도 다른게 있어서 차이점을 알고 사용하면 좋다

 

6단계

21. select row_number() over(order by rating desc) as rk ,name,rating from lol_users ;

22. select name from lol_users where join_date = (select min(join_date) from lol_users);

23. select row_number() over(partition by region  order by rating desc) as rk ,name,rating,region from lol_users ;

24. select avg(rating),region from lol_users group by region;

 


6단계에서 배울 수 있는건

 

1.row_number( )

 

    조회된 결과에 번호를 지정해 주는 함수며 기본 사용법은 아래처럼 사용

row_number() over(order by id desc)

 

참고

https://sobob.tistory.com/55

 

2.집계함수

 

마무리..

 중간에 다른 할 것도 생기고 테이블도 만들어가며 복습하다 보니 생각보다 지연되어서 마무리를 못한거 같다 ㅜ

 하지만 천천히 나가더라도 기본이 탄탄한게 중요하니 다시 열심히 복습해보자!

 

 

 

 

 

 

 

* 혼자 공부하며 작성하는 글이다 보니 틀린 부분이나 궁금한 부분이 있다면 댓글 부탁드립니다! *