惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The GitHub Blog
The GitHub Blog
MyScale Blog
MyScale Blog
爱范儿
爱范儿
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
Y
Y Combinator Blog
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
Martin Fowler
Martin Fowler
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
M
MIT News - Artificial intelligence
博客园 - Franky
V
Visual Studio Blog
I
InfoQ
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
博客园 - 司徒正美
L
LangChain Blog

博客园 - K3

什么是URL,URI或URN? 软件设计思想的一些文章 (持续补充中) Mac OS X 上Lua的安装方法 Objective C - 4 - 下载图片并且加载到View Objective C - 3 - 实现一个计算器 Objective C - 2 - 随机数,可变字符串,字符串,SubString Objective C - 1 - 实现一个MessageBox.Show List connected users–similar to task manager How to compose namespaces? Hide/Show running Console Calculate drive total/free/available space C# list installed softwares How to: Modify a Project System So That Projects Load in Multiple Versions of Visual Studio PS:WINRAR制作32位安装程序和64位安装程序选项 使用WINRAR来制作安装程序 impersonate a user VBScript - CUD registry key and value mysql script for dynamic running sql script XmlElement可以避免由XmlSerializer多余生成的代码
MySQL 存储过程,游标,临时表创建
K3 · 2014-04-04 · via 博客园 - K3
-- --------------------------------------------------------------------------------
-- 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语法都不一致,写一点东西查半天资料,耽误时间.