프로그래머스 #sql #mysql #oracle(16)
-
[mysql/oracle] 특정 옵션이 포함된 자동차 리스트 구하기
문제 정답 mysql / oracle 1 2 3 4 SELECT * from car_rental_company_car where options like '%네비게이션%' order by car_id desc cs 네비게이션이 있는 options를 고르기위해 like를 사용하면 된다.
2023.02.09 -
[mysql/oracle] 자동차 평균 대여 기간 구하기
문제 정답 mysql 1 2 3 4 5 SELECT car_id ,round(avg(datediff(end_date,start_date)+1),1) average_duration from CAR_RENTAL_COMPANY_RENTAL_HISTORY group by car_id having avg(datediff(end_date, start_date)+1) >= 7 order by average_duration desc ,car_id desc Colored by Color Scripter cs mysql에서는 날짜의 차이를 구해주는 datediff()를 이용하면 된다. datediff(끝날짜, 시작날짜) 빌린 당일에 반납하면 1일로 쳐야하므로 대여일수, 이용일수 등을 구할 때는 +1을 절대 잊으면 안 된다..
2023.02.09 -
[mysql/oracle] 3월에 태어난 여성 회원 목록 출력하기
문제 결과 mysql 1 2 3 4 5 6 7 SELECT member_id, member_name, gender , date_format(date_of_birth, '%Y-%m-%d') date_of_birth from member_profile where gender = 'W' and month(date_of_birth) = '03' and tlno is not null order by member_id Colored by Color Scripter cs oracle 1 2 3 4 SELECT member_id, member_name, gender , to_char(date_of_birth, 'yyyy-mm-dd') date_of_birth from member_profile where gender ..
2023.02.03 -
[mysql/oracle] 입양 시각 구하기(1)
문제 결과 mysql 1. date_format 1 2 3 4 5 SELECT date_format(datetime, '%H') hour, count(*) COUNT from animal_outs where date_format(datetime, '%H') between 9 and 19 group by date_format(datetime, '%H') order by HOUR Colored by Color Scripter cs 처음에 date_format으로 풀었는데 생각해보니까 시간 하나만 뽑으면 되는 거라서 hour을 사용하면 된다. 2. hour 1 2 3 4 5 SELECT hour(datetime) hour, count(*) COUNT from animal_outs where hour(datet..
2023.02.03 -
[mysql / oracle] 가격대 별 상품 개수 구하기
문제 결과 mysql / oracle 1. case문 이용 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 SELECT (case when price >= 0 and price = 10000 and price = 20000 and price = 30000 and price = 40000 and price = 50000 and price = 60000 and price = 70000 and price = 80000 and price = 0 and price = 10000 and price = 20000 and price = 30000 and price = 40000 and price = 50000 and price = 60000 and pri..
2023.02.03 -
[mysql/oracle] 자동차 종류 별 특정 옵션이 포함된 자동차 수 구하기
문제 결과 mysql / oracle 1 2 3 4 5 SELECT car_type, count(*) cars from car_rental_company_car where options like '%시트%' group by car_type order by car_type cs 공교롭게도 요구한 통풍시트, 열선시트, 가죽시트 모두 '시트'가 들어가서 like와 와일드카드로 처리했다. 정규식으로도 가능하다. 1 2 3 4 5 SELECT car_type, count(*) cars from car_rental_company_car where options regexp '시트' group by car_type order by car_type cs 정규식 검색 . : 문자 하나 * : 앞에 나온 문자의 0개 이상..
2023.01.29