在access中这样的SQL语句怎么写?

gzllich 2005-03-05 08:43:37
一定要在Access中实现哦
通过调薪记录列出员工各月基本工资,要求每月以最后一次调薪记录为当月基本工资:
调薪记录表txls结构如下:
date empno salary
-------------------------------
2005-01-02 P001 2000.00
2005-01-10 P001 2500.00
2005-02-11 P001 2800.00
2005-02-25 P001 3000.00
2005-01-10 P002 2800.00

我要得出这样的结果:
Year Month empno salary
-------------------------
2005 01 P001 2500.00
2005 02 P001 3000.00
2005 01 P002 2800.00
...全文
141 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzllich 2005-03-14
  • 打赏
  • 举报
回复
唉,都不行,算了还是在前台程序里面写吧
78hgdong 2005-03-05
  • 打赏
  • 举报
回复
同意!
gxgyj 2005-03-05
  • 打赏
  • 举报
回复
select temp.Year,temp.Month,Empno,max(salary) as Salary
from
(select year([date]) as [year],month([date]) as [Month],max(day(date)) as d,empno,salary from t group by year([date]),empno,month([date]),salary) as temp
group by temp.year,empno,temp.month

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~测试结果:
Year Month Empno Salary

2005 01 P001 2500
2005 02 P001 3000
2005 01 P002 2800
zhangwei1437 2005-03-05
  • 打赏
  • 举报
回复
取每个月的最大的日期,按照人分组
caiso 2005-03-05
  • 打赏
  • 举报
回复
顶一下
Nobu 2005-03-05
  • 打赏
  • 举报
回复
d
见丰 2005-03-05
  • 打赏
  • 举报
回复
up,有点意思,一定要用sql写?
gxgyj 2005-03-05
  • 打赏
  • 举报
回复
d
gxgyj 2005-03-05
  • 打赏
  • 举报
回复
把楼主的表名代换进去...t--->txls,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
select temp.Year,temp.Month,Empno,max(salary) as Salary
from
(select year([date]) as [year],month([date]) as [Month],max(day(date)) as d,empno,salary from TXLS group by year([date]),empno,month([date]),salary) as temp
group by temp.year,empno,temp.month

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~测试结果:
Year Month Empno Salary

2005 01 P001 2500
2005 02 P001 3000
2005 01 P002 2800

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧