用asp+mysql实现计算上下两条记录的差,大神快来呀!!

memoryspace888 2016-09-04 03:56:01
现有数据库表JCD_INFO,
id a time gc1 gc2 gc3
3 LG2 2014/4/24 12 22 33
5 LG2 2016/8/31 15 24 35
22 LG1 2013/2/10 18 25 36
7 LG2 2015/7/31 14 23 34
,我想用将上表中数据取出LG2的所有数据后,按time排序后,再用mysql语句求出gc1,gc2,gc3字段(下减上)两个数的差值,最终实现结果如下:


id a time cz1 cz2 cz3
3 LG2 2014/4/24 0 0 0
7 LG2 2015/7/31 2 1 1
5 LG2 2016/8/31 1 1 1

请教大家如何用mysql实现! 程序为 ASP,数据库MDB,名称JCD_INFO。。
弄了半天,也弄不明白,貌似不简单!!1
...全文
1282 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tzmtx 2017-06-05
  • 打赏
  • 举报
回复
用mysql语句写mdb数据库,闹哪样啊
ACMAIN_CHM 2016-09-04
  • 打赏
  • 举报
回复
错误提示是什么?
memoryspace888 2016-09-04
  • 打赏
  • 举报
回复
引用 2 楼 ACMAIN_CHM 的回复:
基本按下面思路做吧。 如果0因为没有记录,则使用IFNULL来做判断。 select id ,a ,time, gc1 - (select gc1 from JCD_INFO where a=j.a and time<j.time order by time desc limit 1) as cz1, gc2 - (select gc2 from JCD_INFO where a=j.a and time<j.time order by time desc limit 1) as cz2, gc3 - (select gc3 from JCD_INFO where a=j.a and time<j.time order by time desc limit 1) as cz3 from JCD_INFO j where a='LG2'
你好,测试为啥通不过呢???!!!
memoryspace888 2016-09-04
  • 打赏
  • 举报
回复
直接赋值,强制为0,三行是因为只查询a=LG2的数据。。。 id a time gc1 gc2 gc3 3 LG2 2014/4/24 12 22 33 5 LG2 2016/8/31 15 24 35 22 LG1 2013/2/10 18 25 36 7 LG2 2015/7/31 14 23 34 查询后。。。。。 3 LG2 2014/4/24 12 22 33 7 LG2 2015/7/31 14 23 34 5 LG2 2016/8/31 15 24 35 查询后,下面的一行减一面一行,最顶上一行,直接为0 id a time cz1 cz2 cz3 3 LG2 2014/4/24 0 0 0 7 LG2 2015/7/31 (14-12) (23-22) (34-33) 5 LG2 2016/8/31 (15-14) (24-23) (35-34)
ACMAIN_CHM 2016-09-04
  • 打赏
  • 举报
回复
基本按下面思路做吧。 如果0因为没有记录,则使用IFNULL来做判断。 select id ,a ,time, gc1 - (select gc1 from JCD_INFO where a=j.a and time<j.time order by time desc limit 1) as cz1, gc2 - (select gc2 from JCD_INFO where a=j.a and time<j.time order by time desc limit 1) as cz2, gc3 - (select gc3 from JCD_INFO where a=j.a and time<j.time order by time desc limit 1) as cz3 from JCD_INFO j where a='LG2'
ACMAIN_CHM 2016-09-04
  • 打赏
  • 举报
回复
3 LG2 2014/4/24 0 0 0 这行数据怎么来的? 三个0,0.0是如何计算得出的? 另外为什么结果中只有三行了?

7,732

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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