没解决的面试题

有表格如下:
create table  worker2s(id int primary key,name varchar(12),department varchar(12),salary int,releaseDay date);


id 编码
name 姓名
department 部门
salary 工资
releaseDay 发放日期 格式 2009-10-10

现在要求写出sql语句:

找出曾经在任何一个月发了两次或者两次工资以上的员工信息,当月工资发放次数,工资总数,发放月份;


5个回答

select count(salary) times, sum(salary) sum_salary, substr(char(releaseday),1,7) month, name, department from worker2s group by name, department, substr(char(releaseday),1,7) having count(*) > 1;

我用derby试验的,char()是转换函数

select sum(salary), count(id) cnt, substrb(to_char(createdate,'yyyymmdd'),1,6) from worker2s group by substrb(to_char(createdate,'yyyymmdd'),1,6) having cnt > 1

[code="sql"]
select * from worker2s where (id || '') in (select ids from (select count(id) RN,wmsys.wm_concat(id) ids from worker2s group by name,to_date(to_char(releaseDay,'YYYY-MM'),'YYYY-MM')) RN > 1)
[/code]

select count(t.releaseDay),sum(t.salary),t.releaseDay from worker2s t group by t.releaseDay having count(t.releaseDay) > 1

一定给分:
我测试过了可以满足你的要求:
select uname,trunc(utime,'mm') money,count(*) count,sum(money) money from worker2s
group by uname,trunc(utime,'mm')
having count(*)>1

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问