I am new to SQL and have been working through the course and I’m not working on the Warby Parker Project and I’d like to complete a more in-depth analysis of questions 2-5 by looking at the “gender” of the user based on how the first question was answered. This would gain insight in how Male and Female respondents answered the other 4 questions, but specifically wanting to look at question 5. “When was your last eye exam” to see if men or women are more likely to respond. I wrote an SQL query to create a temporary table and assign a “gender” which I joined back to the survey table which returned what appears to be what I am looking for, but I don’t know how to proceed.
CREATE TEMPORARY TABLE gender AS
SELECT CASE
WHEN response = "Men's Styles" THEN 'Male'
WHEN response = "Women's Styles" THEN 'Female'
ELSE "Prefer Not to Answer"
END AS "Gender",
user_id
FROM survey;
SELECT survey.user_id, survey.question, survey.response, gender
FROM survey
JOIN gender
ON survey.user_id = gender.user_id;
I have tried “GROUP BY” and did not get the intended results. I have also tried adding a WHERE clause but got no results back (and no errors)…
SELECT survey.user_id, survey.question, survey.response, gender
FROM survey
JOIN gender
ON survey.user_id = gender.user_id
WHERE survey.question = "5. When was your last eye exam?";