Swap Two Records in SQL Table | Tricky SQL Interview Problem Explained

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

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

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

    Use 3 cases where
    1) id is max
    2)id is even
    3)id is odd

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

    SELECT CASE
    WHEN ID =
    (SELECT MAX(ID)
    FROM COUNTRY_DIRECTORY) THEN ID
    WHEN MOD(ID,
    2) = 1 THEN ID + 1
    ELSE ID-1
    END AS ID,
    COUNTRY
    FROM COUNTRY_DIRECTORY
    ORDER BY ID;

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

      Great!!!! That is the expected solution.. Keep it up and try other problems to improve your SQL skills