TCS SQL Interview Question - Find product wise total amount, including products with no sales

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

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

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

    I didn’t get the defining the months part …. Plz would u please explain why should we do that..

  • @biswajitpradhan6121
    @biswajitpradhan6121 4 месяца назад +3

    for dynamic solution :
    with cte1(pid , pname , _year , _month) as
    (
    select A.pid ,A.pname , datepart(year,B.sold_date) as 'year' , 1 as 'month' from products A , transcations B
    group by A.pid , A.pname , datepart(year,B.sold_date)
    union all
    select pid , pname , _year , _month + 1 from cte1
    where _month + 1

  • @ritammoharana4219
    @ritammoharana4219 4 месяца назад +1

    with cte as (
    select generate_series(1,12) as month,2024 as year)
    select p.pid,p.pname,c.year,c.month,COALESCE(sum(t.amount),0) as total_sales
    from cte as c cross join productp1 as p
    left join transcations as t
    on c.month = date_part('month',t.sold_date) and p.pid = t.pid
    group by p.pid,p.pname,c.year,c.month
    order by p.pid,c.month;
    this query is for postgresql.

  • @maheshnagisetty4485
    @maheshnagisetty4485 4 месяца назад +1

    Nice Video Bro,but i have a doubt if in case year will select dynamically(not in hardcore) how we will do that?

    • @CloudChallengers
      @CloudChallengers  4 месяца назад +1

      @maheshnagisetty4485, Thanks for the feedback.
      You can declare year.
      DECLARE @Year INT = 2024;
      SELECT @Year AS Year, ........................

  • @Ujjwalmishra-t1w
    @Ujjwalmishra-t1w 2 месяца назад +1

    Hello everyone welcome back to the channel

  • @Harish0402
    @Harish0402 3 месяца назад

    how we can achieve
    this scenario in oracle

  • @mohanprasanthmanickam8292
    @mohanprasanthmanickam8292 5 месяцев назад +1

    Thanks for the video.

    • @CloudChallengers
      @CloudChallengers  5 месяцев назад

      @mohanprasanthmanickam8292, Thanks for your comments.

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

    Cross apply mean cross join??

  • @peterparker4358
    @peterparker4358 Месяц назад +1

    One thing one total sales must sales * qty

    • @CloudChallengers
      @CloudChallengers  Месяц назад +1

      @peterparker4358, great catch. Thanks for highlighting.

  • @nr_creations9734
    @nr_creations9734 5 месяцев назад +1

    Very useful

    • @CloudChallengers
      @CloudChallengers  5 месяцев назад

      @nr_creations9734, Thanks for the encouragement.

  • @asadahmad8047
    @asadahmad8047 4 месяца назад +1

    This question is asked to how much experienced person

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

      @asadahmad8047, this question is asked for experienced candidate with 4+ years of experience.

    • @MubarakAli-qs9qq
      @MubarakAli-qs9qq 3 месяца назад

      But this was a very easy one

  • @chandanpatra1053
    @chandanpatra1053 5 месяцев назад +1

    is that question asked to an data engineer/data analyst or is that question asked for a sql developer role.can you please clarify?

    • @CloudChallengers
      @CloudChallengers  5 месяцев назад

      @chandanpatra1053, this question is asked for data engineer role.

  • @vijaygupta7059
    @vijaygupta7059 5 месяцев назад +2

    I have done using MSSQL DB :
    with r_cte as
    (
    Select distinct p.pid, pname
    , case when sold_date is not null then year(sold_date) else '2024' end as years
    , 1 as month from products as p left join transcations as t
    on p.pid = t.pid
    union all
    Select pid, pname, years , (month+1) as month from r_cte
    where month

    • @CloudChallengers
      @CloudChallengers  5 месяцев назад

      @vijaygupta7059, Thanks for posting the alternative approach. Keep posting different approaches for upcoming videos as well.

    • @vlog.444
      @vlog.444 5 месяцев назад +1

      Thanks for the video