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

- checkin21345678 October 31, 2017 | Flag Reply
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

- Jegan V November 29, 2017 | Flag Reply
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

- jegan.velappan November 29, 2017 | Flag Reply
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

- Anonymous February 28, 2018 | Flag Reply
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

- Anonymous February 28, 2018 | Flag Reply
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;

- Buvan March 22, 2018 | Flag Reply
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;

- Buvan March 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it should be sum and not count

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

- sid November 15, 2018 | Flag


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More