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 4 years 3 Answers 875 views Great Grand Master 0

Answers ( 3 )

  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

  3. SELECT name
    FROM (SELECT rownum as RN , name
    FROM tablename)
    WHERE MOD(RN,3)=0
    OR MOD(RN,7)=0
    AND MOD(RN,21)0 ;

Leave an answer

Browse
Browse