Programmers/SQL(34)
-
[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 1 2 3 4 5 SELECT mcdp_cd 진료과코드, count(*) 예약건수 from APPOINTMENT where date_format(apnt_ymd, '%Y-%m') = '2022-05' group by mcdp_cd order by count(*), 진료과코드 cs oracle 1 2 3 4 5 SELECT mcdp_cd 진료과코드, count(*) 예약건수 from APPOINTMENT where to_char(apnt_ymd, 'yyyy-mm') = '2022-05' group by mcdp_cd order by count(*), 진료과코드 cs 먼저 where절로 2022년 5월 자료만 뽑아내고 진료과코드별로 그룹을 묶어주면 된다.
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