본문 바로가기

SQL

SQL 총연습 (1)

입양 시각 구하기(1)

SELECT hour(DATETIME) as HOUR, count(*) COUNT
from ANIMAL_OUTS
where  9 <= hour(DATETIME) and hour(DATETIME) < 20
group by 1
order by HOUR

 

진료과별 총 예약 횟수 출력하기

SELECT MCDP_CD '진료과코드', count(*) '5월예약건수'
from APPOINTMENT
where APNT_YMD like('2022-05%')
group by MCDP_CD
order by count(*), MCDP_CD

 

자동차 종류 별 특정 옵션이 포함된 자동차 수 구하기

SELECT CAR_TYPE, 
        count(*) CARS
from CAR_RENTAL_COMPANY_CAR
where OPTIONS like ('%통풍시트%') or 
    OPTIONS like('%열선시트%') or 
    OPTIONS like('%가죽시트%')
group by CAR_TYPE
order by 1

 

오랜 기간 보호한 동물(2)

select i.ANIMAL_ID, i.NAME
from ANIMAL_INS i
    inner join ANIMAL_OUTS o
        on i.ANIMAL_ID = o.ANIMAL_ID
order by o.DATETIME - i.DATETIME desc limit 2

 

루시와 엘라 찾기

SELECT ANIMAL_ID, NAME, SEX_UPON_INTAKE
from ANIMAL_INS
where NAME in ('Lucy', 'Ella', 'Pickle', 'Rogan', 'Sabrina', 'Mitty')
order by 1

'SQL' 카테고리의 다른 글

SQL 총연습 (2)  (0) 2024.12.31
SELECT 연습(4)  (0) 2024.12.20
SELECT 연습(3)  (1) 2024.12.19
SELECT 연습(2)  (2) 2024.12.18
SELECT 연습(1)  (0) 2024.12.17