易截截图软件、单文件、免安装、纯绿色、仅160KB

球一句sql - .NET技术 / ASP.NET

table A

id income
1 120
2 211
3 116
........


table sum

id total
1 120 --1
2 331 --1+2
3 447 --1+2+3
........


如何按天汇总以来的收入,sql怎么写
select sum(Income) from Table
where Date between StartDate and EndDate

搂主表述不清楚啊。。。。。。上面的就是sum了,自己搞清楚了很好写的,无非是group by和inner join之类的。。。



1 120 
2 331 
3 447 

这个是根据table A 输出的sum表


引用
SQL code
DECLARE @t TABLE (id int,income int)
INSERT INTO @t
SELECT 1 ,120
UNION ALL SELECT 2, 211
UNION ALL SELECT 3 ,116


SELECT b.id,
(SELECT SUM(a.income) from @t a WHERE a.id<=b.id……


游标也可以,不过楼上的更简洁点。

引用
SQL code
DECLARE @t TABLE (id int,income int)
INSERT INTO @t
SELECT 1 ,120
UNION ALL SELECT 2, 211
UNION ALL SELECT 3 ,116


SELECT b.id,
(SELECT SUM(a.income) from @t a WHERE a.id<=b.id……


学习……

哈哈,明白了

对了,那select * from a如何赋给@t呢哦!

请教LZ
可不可以给我稍微讲一下
“SELECT b.id, 
  (SELECT SUM(a.income) from @t a


相关问答:

asp.net程序员求职 - .NET技术 / 非技术区

本人工作经验一年以上
熟悉asp.net
熟悉javascript
熟悉Css
熟悉ajax
熟悉sqlserver2005
有一年的项目经验
具体项目和其他的就不在这写了
有意者联系:
QQ:359233910
引用
本人工作经验一年以上
熟悉asp ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

求一个SQL语句 - MS-SQL Server / 基础类

字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......

sql 问题 - MS-SQL Server / 基础类

需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号