Leetcode Hard 1225: Find Continuous Dates META Advanced SQL Data Science Interview Question Solved!

Поделиться
HTML-код
  • Опубликовано: 14 дек 2024

Комментарии • 7

  • @anuragshrivastava7855
    @anuragshrivastava7855 4 месяца назад

    bdiya bhai

  • @roymou5856
    @roymou5856 8 месяцев назад

    awesome, thanks. i was thinking we can filter out unwanted dates at the very beginning itself:
    with cte as
    (
    select * from
    (
    select
    fail_date as dateState,
    'failed' as state
    from Failed
    union
    select
    success_date as dateState,
    'succeeded' as state
    from Succeeded
    ) t
    where dateState between '2019-01-01' and '2019-12-31'
    order by dateState
    ),
    rnkDate as
    (
    select
    dateState,
    state,
    rank() over (partition by state order by dateState) as rnkDate
    from cte
    ),
    grpMarker as
    (
    select
    *,
    date_sub(dateState,interval rnkDate DAY) as grpMarker
    from rnkDate
    )
    select
    state as period_state ,
    min(dateState) as start_date ,
    max(dateState) as end_date
    from grpMarker
    group by grpMarker, state

    • @EverydayDataScience
      @EverydayDataScience  8 месяцев назад +1

      Yes, filtering early in real-world problems especially when dealing with millions of rows is usually a better option. Since I was trying to demonstrate the concept, I filtered it at the very end.

    • @roymou5856
      @roymou5856 8 месяцев назад

      @@EverydayDataScience thank you making all these videos. it helped me a lot gaining my confidence to attempt writing medium and hard SQL. Great job. Please share more videoa and help us learning the key concepts.

  • @xiamojq621
    @xiamojq621 8 месяцев назад

    thank bro