SQL interview question | Conditional Query
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 6 )
Select gender, count(*)
From Employees where DOB
Between ’01/01/1960′ and ’31/12/1975′
Group by sex
select count(1) as Employee_Cnt , sex
FROM Employees
WHERE DOB between 01/01/1960 AND 31/12/1975.
GROUP BY sex
Select Sex,Count(*) as No_employees
From Employees
Where DOB between ’01/01/1960′ and ’31/12/1975′
Group by Sex;
select sex, count(*) as no_of_employees
from employees where DOB between ’01/01/1960′ and ’31/12/1975′
group by sex;
Assuming the table is at employee id level;
SELECT sex, count(*) as emp_count
FROM Employees
WHERE DOB BETWEEN ’01-01-1960′ AND ’31-12-1975′
GROUP BY sex
/*When you use the BETWEEN operator with date values, to get the best result, you should use the type cast to explicitly convert the type of column or expression to the DATE type*/
Select count(*) as Number_of_Employees
from Employees
where DOB BETWEEN CAST(‘1960-01-01’ as DATE) and CAST(‘1975-12-31’ as DATE)
Group by Sex;