表名为salary (收入表)
字段:name varchar(20) (姓名)
month int (月份)
income int (收入)
我要查询出的结果集为:
姓名 当前月的收入 上个月的收入
谢谢大家赐教!
字段:name varchar(20) (姓名)
month int (月份)
income int (收入)
我要查询出的结果集为:
姓名 当前月的收入 上个月的收入
谢谢大家赐教!
解决方案 »
- 2008导出脚本在2000运行出错
- 求助一句SQL语句
- 有没有好方法求出每个分类最大值出现时间?
- 获取多个栏目下的新闻,怎么写SQL语句?
- 自引用表如何级联删除???
- select语句的top问题
- 在查询中,如何将两个表的对应字段组合成一个字段呢,详情请进......
- where the current log sequence number stored?
- 已用于出版的表,怎么使触发器临时失效?Alter table disable trigger mytrigger不行呀
- 装net当心你的sql server 7
- 增加表的主键约束
- 关于profiler 里的 reads wites 的问题
insert into @salary select '王',11,1300
insert into @salary select '王',12,1400
insert into @salary select '李',11,1500
insert into @salary select '李',12,1600
insert into @salary select '李',12,1700select distinct(name),
当前月收入=(select isnull(sum(income),0) from @salary where name=a.name and [month]=month(getdate()) ),
上月收入=(select isnull(sum(income),0) from @salary where name=a.name and [month]=month(getdate())-1)
from @salary a李 3300 1500
王 1400 2500