如何增加一列,使每一行此列的数据等于前面所有行某一列之和 sql 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 create table tb(id int,date datetime,[count] int,[type] int)insert into tb select 1,'2014-1-1',5,1insert into tb select 2,'2014-1-2',4,2 insert into tb select 3,'2014-1-2',3,1insert into tb select 4,'2014-1-3',7,2insert into tb select 5,'2014-1-3',6,1 goselect *,(select sum([count]) from tb where id<=a.id and [type]=a.[type])as s from tb a/*id date count type s----------- ----------------------- ----------- ----------- -----------1 2014-01-01 00:00:00.000 5 1 52 2014-01-02 00:00:00.000 4 2 43 2014-01-02 00:00:00.000 3 1 84 2014-01-03 00:00:00.000 7 2 115 2014-01-03 00:00:00.000 6 1 14(5 行受影响)*/godrop table tb 另外 我想问一下 如果数据量比较大的情况下,这样做查询会不会影响效率.会影响效率的,最高改成 join的那种 SQL Server 中怎么删除一个列(不知道是否被其它表引用) 求查询 更新语句去掉空格 大家帮我看看这个存储过程怎么出错呢~ 求一条更新语句? 如何查询数据表的最后更改时间? help~~~为何添加附加数据库时失败??请指教:( 存储过程相关 执行EXEC master..xp_cmdshell存储过程,提示‘命令行有未知参数“and”’问题 请问如何使用clientdataset向应用服务器插入一条记录 sql server 2008 数据库备份还原问题 sql server2008r2问题,急急急
insert into tb select 1,'2014-1-1',5,1
insert into tb select 2,'2014-1-2',4,2
insert into tb select 3,'2014-1-2',3,1
insert into tb select 4,'2014-1-3',7,2
insert into tb select 5,'2014-1-3',6,1
go
select *,(select sum([count]) from tb where id<=a.id and [type]=a.[type])as s from tb a
/*
id date count type s
----------- ----------------------- ----------- ----------- -----------
1 2014-01-01 00:00:00.000 5 1 5
2 2014-01-02 00:00:00.000 4 2 4
3 2014-01-02 00:00:00.000 3 1 8
4 2014-01-03 00:00:00.000 7 2 11
5 2014-01-03 00:00:00.000 6 1 14(5 行受影响)*/
go
drop table tb
另外 我想问一下 如果数据量比较大的情况下,这样做查询会不会影响效率.会影响效率的,最高改成 join的那种