SQL CASE or IF Else Condition [message #681705] |
Mon, 17 August 2020 12:20  |
|
Hi Everyone,
I am stuck in query making and spend my whole day but didn't succeeded yet.
My Requirement is to extract the data of employees from EMP Table only. Each Employee have different type of Emails like (Yahoo, Gmail and Hotmail) and each mail type have different code like (Yahoo have 1, Gmail have 2 and Hotmail have 3) Some employees have all three and some have two of them and some have only one.
Now i want a query which extract the data WHEN an employee have 1(Yahoo) and 2(Gmail) mail then query should prioritize 1(Yahoo) and show only one row with code 1(Yahoo), But when Employee have all three mails(1,2,3) then query should show all the rows for that specific employee.
When employee have only two mails then it should show only one row which have code 1.
Please help, as i have tried with CASE and DECODE but it didn't work. Using UNION ALL Worked but that created a lag on system.
|
|
|
|
Re: SQL CASE or IF Else Condition [message #681707 is a reply to message #681705] |
Mon, 17 August 2020 13:38  |
Solomon Yakobson
Messages: 3212 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
wasimK wrote on Mon, 17 August 2020 13:20
When employee have only two mails then it should show only one row which have code 1.
What if employee has two email addresses and none of them is Yahoo (code 1): Gmail and Hotmail. Also, is employee id, email type combination unique? And, as Michel already noted, please provide CREATE TABLE and INSERT data statements. In any case, all you need is analytic COUNT.
SY.
|
|
|