Tricky sort | Data engineer | SQL Problem Statement | SQL Quiz

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

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

  • @saisai-st1jv
    @saisai-st1jv Год назад +1

    select id from (select id, row_number() over(order by id asc) from tricky_sort where id>=0 union select id, row_number() over(order by id desc) + (select count(1) from tricky_sort where id>=0 ) from tricky_sort where id

    • @DataArchitectStudio
      @DataArchitectStudio  Год назад

      Good... understand your approach.. think any other way to solve this..

  • @HARSHRAJ-gp6ve
    @HARSHRAJ-gp6ve 2 месяца назад +1

    with cte as(
    select numbers.*,ROW_NUMBER()OVER() as x1,'A' as val FROM numbers where ID>=0 ORDER BY ID
    ),cte1 as(
    select numbers.*,ROW_NUMBER()OVER() as x2,'b' as val FROM numbers where ID

    • @DataArchitectStudio
      @DataArchitectStudio  2 месяца назад

      @HARSHRAJ-gp6ve good but always think for simple solution.
      Hint: CASE WHEN statement comes handy in these scenarios.

  • @venkatakamaiah46
    @venkatakamaiah46 Год назад

    select id from
    (select id,1 as num from num_order where id>=0
    union
    select id,2 as num from num_order where id