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
SQL
55 years
3 Answers
1010 views
Great Grand Master 0
Answers ( 3 )
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)
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
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 ;