inblog logo
|
silver
    SQL문제풀기

    [SQL문제풀기] 다음날도 서울숲의 미세먼지 농도는 나쁨 😢

    silver's avatar
    silver
    Mar 02, 2025
    [SQL문제풀기] 다음날도 서울숲의 미세먼지 농도는 나쁨 😢
    Contents
    문제SQLiteMYSQL에서 날짜 더하기ORACLE에서 날짜 더하기

    문제

    solvesql.com
    solvesql.com
    https://solvesql.com/problems/bad-finedust-measure/

    SQLite

    내가 작성한 정답

    select today.measured_at today, next.measured_at next_day, today.pm10, next.pm10 next_pm10 from measurements today join measurements next on date(today.measured_at,'+1 day') = next.measured_at where today.pm10 < next.pm10
     

    SQLite에서 날짜 더하기

    1. 년 더하기 date(column, ‘+1 year’)
      1. notion image
    1. 월 더하기 date(column, ‘+1 month’)
      1. notion image
    1. 일 더하기 date(column,’+1 day’)
    notion image

    SQLite에서 날짜 빼기

    : 특정 일 수를 더하거나 빼는 거라면 위의 방법과 같이 date(컬럼, ‘+-일,월,년 day,month,year ‘)로 작성하면된다.
    SELECT (julianday(date1) - julianday(date2)) AS date_difference FROM table;
    notion image
    SELECT strftime('%Y', date1) - strftime('%Y', date2) AS year_difference, strftime('%m', date1) - strftime('%m', date2) AS month_difference, strftime('%d', date1) - strftime('%d', date2) AS day_difference FROM table;
     

    MYSQL에서 날짜 더하기

    DATE_ADD('2025-03-01', INTERVAL 1 DAY) // month, year도 같은 방식으로 하면 된다
    1. 년 더하기
      1. notion image
    1. 월 더하기
      1. notion image
    1. 일 더하기
      1. notion image

    ORACLE에서 날짜 더하기

    1. 년 더하기 : + interval ‘년’ year
      1. notion image
    3. 일 더하기 : datetime형식에 그냥 더하면 된다.
    notion image
    1. 월 더하기 : 1) add_months(column, 월) 2) interval ‘월’ month
      1. notion image
        notion image
     
    Share article

    silver

    RSS·Powered by Inblog