I have CustomerSession table in sql.
I want to do flagging for those user who have visited page 4 as 1 and rest as 0.
result will be like this:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
you can do this with a simple
select *, case when exists ( select * from CustomerSession t2 where t.user=t2.user and t2.page=4 ) then 1 else 0 end flag_4 from CustomerSession t
@Innaya, I’m a bit confused as to your question, but I’ll give it a shot… If what you are looking for is a query…
SELECT Session, [User], Page, flag_4 = CASE WHEN EXISTS (SELECT 1 FROM CustomerSession cs2 WHERE cs2.[User] = cs1.[User] and Page = '4') THEN 1 ELSE 0 END FROM CustomerSession cs1