-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `filter_record_time`(startTime timestamp, endTime timestamp, pointIndex int)
BEGIN
declare _recordtime timestamp;
declare _pointIndex smallint;
declare _value double;
declare _result text;
declare _previoustime timestamp;
DECLARE done INT DEFAULT FALSE; declare fetchSeqCursor cursor for select distinct RecordTime,PointIndex,Value
from flow_record
where recordtime >= startTime
and recordtime < endTime
and pointIndex = pointIndex
and recordtime is not null
order by recordtime; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; create table if not exists filter_record_time_temp(timeFrom timestamp, timeTo timestamp, times int); open fetchSeqCursor; seq_loop:loop
fetch fetchSeqCursor into _recordtime, _pointIndex, _value; IF done THEN
LEAVE seq_loop;
END IF; if _previoustime is null then
if _recordtime <> startTime then
insert into filter_record_time_temp select startTime timefrom, _recordtime timeto,
cast((unix_timestamp(_recordtime) - unix_timestamp(startTime) - 120) / 120 as signed) times;
end if;
else
if unix_timestamp(_previoustime) + 120 < unix_timestamp(_recordtime) then
insert into filter_record_time_temp select _previoustime timefrom, _recordtime timeto,
cast((unix_timestamp(_recordtime) - unix_timestamp(_previoustime) - 120) / 120 as signed) times;
end if;
end if; set _previoustime = _recordtime;
end loop; close fetchSeqCursor; if unix_timestamp(_previoustime) + 120 < unix_timestamp(endTime) then
insert into filter_record_time_temp select _previoustime timefrom, endTime timeto,
cast((unix_timestamp(endTime) - unix_timestamp(_previoustime) - 120) / 120 as signed) times;
end if; select * from filter_record_time_temp; drop table if exists filter_record_time_temp; END

真尼玛烦人,各个数据库sql语法都不一致,写一点东西查半天资料,耽误时间.

MySQL 存储过程,游标,临时表创建的更多相关文章

  1. MySQL存储过程 游标

    MySQL存储过程  游标 如何在存储过程中使用MySQL游标来遍历SELECT语句返回的结果集 MySQL游标简介 要处理存储过程中的结果集,请使用游标.游标允许您迭代查询返回的一组行,并相应地处理 ...

  2. mysql存储过程游标嵌套循环

    自己写的一个mysql存储过程如下: BEGIN DECLARE _did bigint(20);DECLARE _count int;DECLARE s1 int;DECLARE cur_1 CUR ...

  3. mysql 存储过程、视图---创建、调用、删除

    之前一直用的是Sql Server数据库,最近偶然机会接触到mysql.这里总结了关于mysql 存储过程.视图的“创建.调用.删除”示例 ============================== ...

  4. mysql存储过程游标加计划任务事件调度器

    存储过程加事件调度器 -- 存储过程 (多个)游标的使用 临时表的使用(让执行时间从一个小时降低到5分钟)DELIMITER $$ DROP PROCEDURE IF EXISTS `eval_cal ...

  5. 菜鸟使用MySQL存储过程and临时表,供新手参考,请高手斧正

    因为公司最近的一个项目,第一次用到了MySQL(5.10版本),之前听传说MySQL很厉害的样子,因为开源而神奇,但是现在用起来, 感觉并不好啊!我知道是我水平太down,呜呜呜,请各路神仙略施小技, ...

  6. MySQL 存储过程/游标/事务

    将会用到的几个表 mysql> DESC products; +------------+--------------+------+-----+---------+-------------- ...

  7. MySQL存储过程和临时表

    MySQL创建存储过程 MySQL中,创建存储过程的基本形式如下: CREATE PROCEDURE sp_name ([proc_parameter[,...]]) [characteristic ...

  8. php调用mysql存储过程游标

    <?php $dbtype = 'mysql'; $host = 'localhost'; $dbname = 'test'; $dsn = "$dbtype:host=$host;d ...

  9. MySQL 存储过程游标

    一.创建游标 游标用declare语句创建.如下面的例子所示: create procedure test2() begin declare cursorTest cursor for select ...

随机推荐

  1. 【前端】jQuery选择器$()的实现原理

    今天三七互娱技术面试的时候面试官问了我这个问题,当时一脸懵逼,于是好好总结一下. 当我们使用jquery选择器的时候,$(s).回默认去执行jquery内部封装好的一个init的构造函数每次申明一个j ...

  2. redis命令的使用

    批量删除特定前缀的keys redis-cli KEYS "prefix:*" | xargs redis-cli DEL 返回list的长度 > LPUSH test &q ...

  3. unix_timestamp() 和 from_unixtime()

    unix_timestamp() 将时间转换为时间戳.(date 类型数据转换成 timestamp 形式整数) select unix_timestamp('2016-03-23 11:10:10' ...

  4. mysql创建数据库和用户

    create database sonar character set utf8 collate utf8_general_ci; flush privileges; grant all privil ...

  5. HDU 1698 just a hook - 带有lazy标记的线段树(用结构体实现)

    2017-08-30 18:54:40 writer:pprp 可以跟上一篇博客做个对比, 这种实现不是很好理解,上一篇比较好理解,但是感觉有的地方不够严密 代码如下: /* @theme:segme ...

  6. MapReduce-实践2

    进阶实践4:  mapper,reducer输出数据压缩 应用场景 当mapper或者reducer的输出数量比较大,会影响shuffle阶段远程拷贝的网络性能,以及对存储容量的要求:这个时候可以考虑 ...

  7. Lucene 初步 之 HelloWorld

    万恶的源头 HelloWorld 要完成lucene 的配置 需要几个jar包 (如果需要可以留言我私发) 创建索引API分析: 1. Directory: 类代表一个Lucene索引的位置,FSDi ...

  8. authentication vs authorization 验证与授权的区别

    认证和授权的区别 Authentication vs. Authorization简单来说,认证(Authentication )是用来回答以下问题: 用户是谁 当前用户是否真的是他所代表的角色 通常 ...

  9. delphi ScriptGate 调用JS

    在 FireMonkey 使用 TWebBrowser 调用 Javascript函数并获取返回值以及 JavaScript 中调 Delphi 的函数/过程,普遍都在使用老掉牙的URL重定的方法,还 ...

  10. flask学习(九):模板渲染和参数传递

    一. 如何渲染模板 1. 模板放在templates文件夹下 2. 从flask中导入render_template函数 3. 在视图函数中,使用render_template函数,渲染模板 注意:只 ...