Facebook Interview Question
Data EngineersTeam: Search
Country: United States
Interview Type: Phone Interview
Hope the percentage is the Male count divided by the total count and this Cast might not be right. I tried this way (in Teradata). The table is having State and Customer Gender as M or F.
SELECT src.STATE
,SUM(CASE WHEN GENDER = 'M' THEN 1 ELSE 0 END) MALE_COUNT
,COUNT(*) AS TOTAL_COUNT
,SUM(CASE WHEN GENDER = 'M' THEN 1 ELSE 0 END)/CAST(COUNT(*) AS FLOAT) AS RATIO
FROM table_name src
GROUP BY 1
Hope the percentage calculation is count of particular category by the total value. I tried the count option (in Teradata) and the table is having State and Gender of a customer
SELECT src.STATE
,SUM(CASE WHEN GENDER = 'M' THEN 1 ELSE 0 END) MALE_COUNT
,COUNT(*) AS TOTAL_COUNT
,SUM(CASE WHEN GENDER = 'M' THEN 1 ELSE 0 END)/CAST(COUNT(*) AS FLOAT) AS RATIO
FROM table_name src
GROUP BY 1
select gender, area, COUNT(*) / CAST( SUM(count(*)) over (partition by gender) as float)
- checkin21345678 October 31, 2017from table
group by gender, area