axtg86 Posted January 25, 2011 Share Posted January 25, 2011 So here's the deal: I have a question and answer table. The question table specifies whether a question is formulated positively or negatively (qsReversed is 0 or 1). Based on this answer I want to sum the answer values accordingly. If it is not reversed 5=5, if it is reversed 5 should be 1, 4->2, etc. I know exactly how to recode variables in SPSS, but haven't been able to do so using SQL. Closest that I have gotten (no error, no results) is SELECT * FROM questions eq LEFT JOIN answers ea ON eq.qsID=ea.qsID WHERE eq.qsReversed=1 AND ea.answerValue IS NOT NULL AND ea.answerValue = CASE WHEN '5' THEN '1' WHEN '4' THEN '2' WHEN '2' THEN '4' WHEN '1' THEN '5' ELSE '3' END; Thanks for any input anyone might have! Quote Link to comment https://forums.phpfreaks.com/topic/225580-recode-values/ Share on other sites More sharing options...
fenway Posted January 26, 2011 Share Posted January 26, 2011 You're not too far off -- but you want that CASE expression in your select column list, not your WHERE clause. And the LEFT JOIN with IS NOT NULL is really just an INNER JOIN. Quote Link to comment https://forums.phpfreaks.com/topic/225580-recode-values/#findComment-1165686 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.