Walmart Labs Interview Question | Lottery Ticket

Question

You have data of people who have applied for a lottery ticket. The data consists of their ticket number. You have to choose winners by selecting the people present in rows divided by 3 or 7, but not both.

Write a query to make things easy to select the winners.

in progress 1
Dhruv2301 3 months 2 Answers 158 views Great Grand Master 0

Answers ( 2 )

  1. select ticketid,Row_Number(), OVER(Order By ticketid) as rown
    from lottery where (mod(rown,3) == 0 or mod(rown,7) == 0) AND
    (mod(rown,21) != 0)

  2. with newtable as
    (select *,
    row_number() over() as rwn
    from employee1
    )

    select * from newtable
    where rwn%3 =0
    or rwn%7 =0
    and rwn%21 0

Leave an answer

Browse
Browse