## Facebook Interview Question for Data Engineers

Team: Search
Country: United States
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
0
of 0 vote

select gender, area, COUNT(*) / CAST( SUM(count(*)) over (partition by gender) as float)
from table
group by gender, area

Comment hidden because of low score. Click to expand.
0
of 0 vote

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``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

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``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

select round((malecnt/totcnt)*100,2) as percentagemale from
(select cast(sum(case when gender ='m' then 1 else 0 end) as float) as malecnt,
count(*) as totcnt
from table
where area = 'abc') tbl

Comment hidden because of low score. Click to expand.
0
of 0 vote

with cte as
(select cast(count(*) as float) as malecnt
from table
where gender ='m'
and area = 'abc')

select round(malecnt/(select count(*) from table where area =1)*100,2) as malepaercentage
from cte

Comment hidden because of low score. Click to expand.
0
of 0 vote

select (count(case when sex='M' then 1 end)/count(*))*100 as male
from employee;

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````select (count(case when sex='M' then 1 end)/count(*))*100 as male
from employee;``````

Comment hidden because of low score. Click to expand.
0

it should be sum and not count

``select sum(case when sex = 'm' then 1 else 0)/count(*) * 100 from employee;``

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.