SQL Interview Questions | Separate DOB Data of Employess

Question

Write an SQL Query find number of employees whose DOB is between 01/07/1965 to 31/12/1975. Collect the data separately for different gender.
Use column name as sex, DOB table name Employees.

(Hint- Imagine a hypothetical data)

in progress 3
Dhruv2301 55 years 6 Answers 2280 views Great Grand Master 0

Answers ( 6 )

  1. SELECT COUNT(*),
    sex from Employees
    WHERE DOB BETWEEN ’01/07/1965′ AND ’31/12/1975′
    GROUP BY sex;

  2. SELECT sex, COUNT(*) from Employees GROUP BY sex WHERE DOB BETWEEN ’01/07/1965′ AND ’31/12/1975′ ;

  3. select gender, count(employees)
    from employees
    where dob between ’01/07/1965′ and ’31/12/1975′
    group by gender

  4. SELECT COUNT(*) AS SEX FROM EMPLOYEES
    WHERE DOB BETWEEN ‘1965-07-01′ AND 1965-12-31’
    GROUP BY GENDER

  5. Select Count(*) ,Sex from Employees
    WHERE DOB BETWEEN CAST(‘1965-07-01’ as Date) AND CAST(‘1965-12-31’ as Date)

    Note: When you use Between operator with Date Values, It is better to use with CAST Function to get better results.CAST Function helps us to convert the Type of column or expression to the Date Type.

  6. Select sex , count(1) as No_of_emp from employee
    where DOB Between ’01/07/1965′ AND ’31/12/1975′
    Group By sex;

Leave an answer

Browse
Browse