mysql 前后数据求差

mysql 前后数据求差

SELECT 
a.ip,
a.portid,
a.`inocts` AS curr,
@a.inocts AS pre,       
@a.inocts:= a.inocts AS tmp
FROM tb_me60 a,(SELECT @a.inocts:=0)s

SELECT 
b.ip,
b.portid,
b.pre,
b.curr,
(b.curr - b.pre)*8/1024/1024/300 AS diff
FROM
(
SELECT 
a.ip,
a.portid,
a.`inocts` AS curr,
@a.inocts AS pre,       
@a.inocts:= a.inocts AS tmp
FROM tb_me60 a,(SELECT @a.inocts:=0)s
)b;

参考https://blog.csdn.net/yjgithub/article/details/75433345

你可能感兴趣的:(数据库)