SQL interview question | Conditional Query

Question

Write an SQL Query find number of employees
according to gender whose DOB is between 01/01/1960 to
31/12/1975.
Use column name as sex,DOB table name Employees

in progress 1
TheDataMonk 55 years 6 Answers 2414 views Grand Master 0

Answers ( 6 )

  1. Select gender, count(*)
    From Employees where DOB
    Between ’01/01/1960′ and ’31/12/1975′
    Group by sex

  2. select count(1) as Employee_Cnt , sex
    FROM Employees
    WHERE DOB between 01/01/1960 AND 31/12/1975.
    GROUP BY sex

  3. Select Sex,Count(*) as No_employees
    From Employees
    Where DOB between ’01/01/1960′ and ’31/12/1975′
    Group by Sex;

  4. select sex, count(*) as no_of_employees
    from employees where DOB between ’01/01/1960′ and ’31/12/1975′
    group by sex;

  5. 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

  6. /*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;

Leave an answer

Browse
Browse