Uber SQL Interview Question | Find User's third transaction | SQL Window Functions | Advanced SQL

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

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

  • @akshaykodekal8483
    @akshaykodekal8483 8 дней назад

    Very clearly and calmly explained

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

    with cte_trans
    as
    (
    select [user_id],[spend],[transaction_date],dense_rank() OVER(partition by user_id order by transaction_date) as transaction_s from transactions
    )
    Select * from cte_trans where transaction_s=3

  • @aditi_shetti
    @aditi_shetti 25 дней назад

    My take on the question where I have used dense_rank instead of row_number
    with cte1 as (
    select user_id, spend, transaction_date ,
    dense_rank() over(partition by user_id order by transaction_date) as dense_rn
    from transactions_1 )
    select user_id, spend, transaction_date
    from cte1 where dense_rn = 3

  • @gospelmoto2833
    @gospelmoto2833 2 месяца назад +1

    I learned a new thing! Thanks!

  • @badrilalnagar9232
    @badrilalnagar9232 2 месяца назад +1

    Always smiling is a priceless quality of life.

  • @Savenature635
    @Savenature635 18 дней назад

    with cte as (select *,dense_rank() over(partition by user_id order by transaction_date asc) as rnk
    from uber_transactions)
    select user_id,spend,transaction_date from
    cte
    where rnk=3;

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

    with cte as (select user_id,spend,transaction_date,rank() over(partition by user_id order by transaction_date) as rnk from transactions)
    select user_id,spend,transaction_date from cte where rnk =3;

  • @AnandBabu-e5n
    @AnandBabu-e5n 2 месяца назад +2

    with uber as (
    select *, row_number() over(partition by id) as rn from uberdata
    )
    select * from uber where rn % 3 =0;
    I think we need to fetch every 3 rd transaction in table. may be we need to modify like above

    • @astech4407
      @astech4407 Месяц назад

      it is the third transaction partition by id where order by ?

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

    Thanks for the script

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

    third transaction of every user:
    Select * From (Select t1.user_id From Transaction t Where 3= (Select Count(DISTINCT (t2. user_id)) from Transaction where t2.user_id>=t1.user_id group by user_id ) );

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

    I used dense_rank and got the same output

  • @RahulR-zm1ug
    @RahulR-zm1ug 2 месяца назад

    Hey you contant very useful but you more details SQL full course and main domain use it company details python

  • @hairavyadav6579
    @hairavyadav6579 2 месяца назад +1

    i think script is wrong the your date format is year/date/month
    because i facing problem at the time of inserting value.
    so please correct this thing in correct format in mysql fromat is -- year/month/date.

    • @datasciencewithnish
      @datasciencewithnish  2 месяца назад +1

      You're correct. The date format in MySQL should be year/month/day. I’ve corrected the script to follow the correct format. Big thanks for noticing it!

    • @hairavyadav6579
      @hairavyadav6579 2 месяца назад +1

      @@datasciencewithnish
      Thanks ...
      Sometimes it happens by mistake....
      But thank you for making valuable content

  • @samyukthashanmugam7516
    @samyukthashanmugam7516 22 дня назад

    WITH cte AS (
    SELECT
    user_id,
    spend,
    transaction_date,
    ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY transaction_date ASC) AS user_trans
    FROM
    transactions
    )
    SELECT *
    FROM cte
    WHERE user_trans = 3
    ORDER BY user_id;

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

    Can u do it by CTE

    • @AnandBabu-e5n
      @AnandBabu-e5n 2 месяца назад

      with uber as (
      select *, row_number() over(partition by id) as rn from uberdata
      )
      select * from uber where rn % 3 =0;
      Please find the cte expression