任何人都可以尝试如何解决此表结构的查询?

时间:2010-06-01 08:23:58

标签: sql tsql

员工表结构

first_name varchar2(100)
last_name  varchar2(100)
hire_date  date

显示在雇用最多员工的当天雇用的所有员工?

2 个答案:

答案 0 :(得分:1)

试试这个

   select top 1 * from( 
    select count(first_name) as countemp from employee
    where hire_date between DATEADD(day,-7,getdate())
                        and  getdate()
 group by(hire_date)   ) d order by countemp desc

答案 1 :(得分:1)

select first_name, last_name from employee 
where 
DAYNAME(hired_date) = (
select top 1 dow 
from (
select COUNT(first_name) as cnt, DAYNAME(hire_date) as dow 
from employee
group by (dow)
order by cnt desc
)
)

这是用mysql,但我确定在db2,oracle,ms sql server等中有类似的功能。