Capgemini SQL Interview Question 2024 | Transform Rows Into Columns

Поділитися
Вставка
  • Опубліковано 20 січ 2025

КОМЕНТАРІ • 10

  • @devarajululanka6427
    @devarajululanka6427 Місяць тому +3

    select month,
    sum(case when category = 'clothing' then amount end )as clothing,
    sum(case when category = 'electronics' then amount end )as electronics
    from sales_data
    group by month

    • @skilltechath0n
      @skilltechath0n  Місяць тому

      @devarajululanka6427 Great! Keep practicing :) Let us know if you need us to solve any particular question.

  • @mahammadismail773
    @mahammadismail773 Місяць тому

    fantastic

  • @chandramohan-bo5se
    @chandramohan-bo5se Місяць тому +1

    SELECT * FROM SALES_DATA
    SELECT MONTH,MAX(CASE WHEN CATEGORY='ELECTRONICS'THEN AMOUNT END) AS ELECTRONICS
    ,MAX(CASE WHEN CATEGORY='CLOTHING' THEN AMOUNT END) AS CLOTHING
    FROM SALES_DATA
    GROUP BY MONTH ORDER BY MONTH

    • @skilltechath0n
      @skilltechath0n  Місяць тому

      @chandramohan-bo5se Great! Keep practicing :) Let us know if you need us to solve any particular question.

  • @tsidesh5480
    @tsidesh5480 Місяць тому

    Without using crosstab, can do with group by, will the company accept it

    • @skilltechath0n
      @skilltechath0n  Місяць тому

      Yes, how you interpret the problem and solve, it's completely upto you. Everyone has a different way of perceiving the problem and solving it.

  • @ishanshubham8355
    @ishanshubham8355 Місяць тому +1

    select month,
    sum(if(category="electronics",amount,null)) as electronics,
    sum(if(category="clothing",amount,null)) as clothing
    from sales_data
    group by 1
    order by 1;

    • @skilltechath0n
      @skilltechath0n  Місяць тому

      @ishanshubham8355 Great! Keep practicing :) Let us know if you need us to solve any particular question.