Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Oracle SQL: dummy variable from 2 data sets

I have two data tables. They both have an employee id column and a sales quarter column, in addition to lots of other columns. The first, which ill call "Roster", has one row per employee per sales quarter. The second has multiple rows per employee per quarter, with each row being a type of sale made, a column called "salestype" and this second table called "QuarterlySales". Basically, I need to return a number of columns from the first table, but I also need a dummy variable indicating if the employee made a sales type of "cold call".

I tried an if statement but didnt work.

select employeeid, quarter, variablea, variableb, ....., 
if saletype = 'cold call' then 1 else 0 end as ColdCall
from Roster r
left join quarterly sales q
on r.employeeid = q.employeeid
and r.quarter = q.quarter
where blah blah blah conditions;

Im sure my approach is wrong. I welcome any help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If clauses are not possible in this way, you need a case when instead:

...CASE WHEN saletype = 'cold call' THEN 1 ELSE 0 END AS ColdCall...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading