结合日期计算值的SQL

lonan 2009-06-20 11:03:01

欧元 日元 英镑
每日值 3月累积 每日值 3月累积 每日值 3月累积
1/3/2009 +10 +10 +3 +3 -5 -5
2/3/2009 -5 +5 +4 +7 +8 +3
3/3/2009 +2 +7 -2 +5 +10 +13
4/3/2009 +8 +15 -8 -3 - +13
5/3/2009 - +15 +8 +5 +2 +15

其中日期为已知,每日值为已知,月累积需要计算,计算方法是:累加当前计算日期之前的每日值。
日期字段名:selldata,
每日值字段名:sellrate,
欧元、日元、英镑为同个字段名:money,
表为:moneysell

我想根据月份列表,并计算月累积值,如果当月某一天没有输入每日值直接输入“-”,
请教这样的SQL怎样去写啊,要是结合ASP程序要怎样实现这样的排列??????请教高手!!!!!!!
...全文
41 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lonan 2009-06-22
  • 打赏
  • 举报
回复
我贴张图上来吧


其中日期为已知,每日值为已知,月累积需要计算,计算方法是:累加当前计算日期之前的每日值。
如09年4月1号欧元每日值50,月累积50,2号每日值为:6,月累积为1号和2号之和,同理推理....
日期字段名:selldata,
每日值字段名:sellrate,
欧元、日元、英镑为同个字段名:money,
表为:moneysell

列出指定月份,并计算月累积值,如果当月某一天没有输入值直接输入“-”,
SQL怎样去写?,要是结合ASP程序要怎样实现这样的排列
lzp4881 2009-06-22
  • 打赏
  • 举报
回复
<!--#include file="conn.asp"-->

<%
Dim nian : nian="2009"
Dim yue : yue="4"
set rs=conn.execute("select selldate,sum(iif(money='欧元',sellrate,0)) as oy,sum(iif(money='美元',sellrate,0)) as my,sum(iif(money='英镑',sellrate,0)) as yb from moneysell where year(selldate)='"&nian&"' and month(selldate)='"&yue&"' group by selldate order by selldate")

Dim tabStr : tabStr = "<table width='100%' border='1' cellspacing='0' cellpadding='0'>"
tabStr = tabStr & "<tr align='center'>"
tabStr = tabStr & "<td colspan='7'>日期</td>"
tabStr = tabStr & "</tr>"
tabStr = tabStr & "<tr align='center'>"
tabStr = tabStr & "<td> </td>"
tabStr = tabStr & "<td colspan='2'>欧元</td>"
tabStr = tabStr & "<td colspan='2'>美元</td>"
tabStr = tabStr & "<td colspan='2'>英镑</td>"
tabStr = tabStr & "</tr>"
tabStr = tabStr & "<tr align='center'>"
tabStr = tabStr & "<td> </td>"
tabStr = tabStr & "<td>每日</td>"
tabStr = tabStr & "<td>月累积</td>"
tabStr = tabStr & "<td>每日</td>"
tabStr = tabStr & "<td>月累积</td>"
tabStr = tabStr & "<td>每日</td>"
tabStr = tabStr & "<td>月累积</td>"
tabStr = tabStr & "</tr>"

dim mylj : mylj=0
dim oylj : oylj=0
dim yblj : yblj=0
do while not rs.eof
mylj = mylj + rs("my")
oylj = oylj + rs("oy")
yblj = yblj + rs("yb")
tabStr = tabStr & "<tr align='center'>"
tabStr = tabStr & "<td>" & day(rs("selldate")) & "</td>"
tabStr = tabStr & "<td>" & rs("oy") & "</td>"
tabStr = tabStr & "<td>" & oylj & "</td>"
tabStr = tabStr & "<td>" & rs("my") & "</td>"
tabStr = tabStr & "<td>" & mylj & "</td>"
tabStr = tabStr & "<td>" & rs("yb") & "</td>"
tabStr = tabStr & "<td>" & yblj & "</td>"
tabStr = tabStr & "</tr>"
rs.movenext
loop
rs.close

tabStr = tabStr & "<tr align='center'>"
tabStr = tabStr & "<td></td>"
tabStr = tabStr & "<td colspan='2'>年累积:" & conn.execute("select sum(sellrate) from moneysell where year(selldate)='"&nian&"' and money='欧元'")(0) & "</td>"
tabStr = tabStr & "<td colspan='2'>年累积:" & conn.execute("select sum(sellrate) from moneysell where year(selldate)='"&nian&"' and money='美元'")(0) & "</td>"
tabStr = tabStr & "<td colspan='2'>年累积:" & conn.execute("select sum(sellrate) from moneysell where year(selldate)='"&nian&"' and money='英镑'")(0) & "</td>"
tabStr = tabStr & "</tr>"
tabStr = tabStr & "</table>"

response.write tabStr
%>
lonan 2009-06-22
  • 打赏
  • 举报
回复
我的意思是要检索指定的月份,变做上图排列和求和计算。
lonan 2009-06-22
  • 打赏
  • 举报
回复
数据库结构如下

lzp4881 2009-06-22
  • 打赏
  • 举报
回复
你要发数据库结构及数据样例
lonan 2009-06-21
  • 打赏
  • 举报
回复
欧元 日元 英镑
日期 每日值 3月累积 每日值 3月累积 每日值 3月累积
1/3/2009 +10 +10 +3 +3 -5 -5
2/3/2009 -5 +5 +4 +7 +8 +3
3/3/2009 +2 +7 -2 +5 +10 +13
4/3/2009 +8 +15 -8 -3 - +13
5/3/2009 - +15 +8 +5 +2 +15

重发一次,不知道现在会不会变
lzp4881 2009-06-21
  • 打赏
  • 举报
回复
没看明白
xue08161981 2009-06-21
  • 打赏
  • 举报
回复
支持楼主,关注当中
  • 打赏
  • 举报
回复
.....
怎么看不明白呢
lonan 2009-06-20
  • 打赏
  • 举报
回复
上面的没排好!!!
欧元 日元 英镑
日期 每日值 3月累积 每日值 3月累积 每日值 3月累积
1/3/2009 +10 +10 +3 +3 -5 -5
2/3/2009 -5 +5 +4 +7 +8 +3
3/3/2009 +2 +7 -2 +5 +10 +13
4/3/2009 +8 +15 -8 -3 - +13
5/3/2009 - +15 +8 +5 +2 +15

其中日期为已知,每日值为已知,月累积需要计算,计算方法是:累加当前计算日期之前的每日值。
日期字段名:selldata,
每日值字段名:sellrate,
欧元、日元、英镑为同个字段名:money,
表为:moneysell

我想根据月份列表,并计算月累积值,如果当月某一天没有输入每日值直接输入“-”,
请教这样的SQL怎样去写啊,要是结合ASP程序要怎样实现这样的排列??????请教高手!!!!!!!

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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