ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 코드카타
    [스파르타코딩클럽]데이터분석 과정/TIL,WIL 2024. 2. 26. 21:23

     


    SQL 코드카타

    조건별로 분류하여 주문상태 출력하기
    5월 1일을 기준으로 주문 ID, 제품 ID, 출고일자, 출고여부를 조회
    출고여부는 5월 1일까지 출고완료로 이 후 날짜는 출고 대기로 미정이면 출고미정으로 출력
    결과는 주문 ID를 기준으로 오름차순 정렬
    • 출고여부 : case when 
    • 5월 1일까지 출고 완료 :  <= '05-01'
    •  5월 1일 이후 출고 대기 : > '05-01'
    • 정렬 : order by asc
    SELECT order_id, product_id, date_format(out_date, '%Y-%m-%d'),
           case when date_format(out_date,'%m-%d') <='05-01' then '출고완료'
                when date_format(out_date,'%m-%d') > '05-01' then '출고대기'
                else '출고미정'
                end as '출고여부'
    from food_order
    order by order_id asc;

     

    Exchange Seats
    연속된 두 학생마다 좌석 ID를 바꾸기
    학생 수가 홀수인 경우 마지막 학생의 ID는 교환되지 않음
    id를 기준으로 오름차순으로 정렬된 결과 테이블을 반환
    • 홀수인 경우 : id % 2 = 1 then id
    • 연속된 학생 id 바꾸기 :  +1 또는 -1
    • 오름차순 정렬 : order by asc
    SELECT CASE WHEN id = (SELECT MAX(id) FROM seat) AND id % 2 = 1 THEN id 
            WHEN id % 2 = 1 THEN id + 1
            ELSE id - 1
            END AS id,
            student
    FROM seat
    ORDER BY id

     

    Weather Observation Station 18
    a happens to equal the minimum value in Northern Latitude (LAT_N in STATION).
    b happens to equal the minimum value in Western Longitude (LONG_W in STATION).
    c happens to equal the maximum value in Northern Latitude (LAT_N in STATION).
    d happens to equal the maximum value in Western Longitude (LONG_W in STATION).
    Manhattan Distance between point P1 and P2 and round it to a scale of 4 decimal places
    • Manhattan Distance : |x1 - x2| + |y1 - y2| -> abs
    • round it to a scale of 4 decimal places : round(,4)
    select round(abs(min(LAT_N) - max(LAT_N)) + abs(min(LONG_W) - max(LONG_W)), 4)
    from station;

     

    '[스파르타코딩클럽]데이터분석 과정 > TIL,WIL' 카테고리의 다른 글

    코드카타  (1) 2024.02.28
    코드카타 / 태블로  (1) 2024.02.27
    코드카타  (0) 2024.02.23
    코드카타/태블로  (0) 2024.02.21
    심화 프로젝트  (0) 2024.02.20
Designed by Tistory.