• 存储过程--结果集


    /**
    *根据省份id和时间查询不同班次累计域名和url次数
    **/
    DROP PROCEDURE IF EXISTS proc_get_province_count_info;
    
    CREATE PROCEDURE proc_get_province_count_info (
    	IN province_id INT,
    	IN start_time  varchar(50),
    	IN end_time  varchar(50),
    	OUT domain_count INT,
    	OUT url_count INT,
    	OUT last_domain_count INT,
    	OUT last_url_count INT
    
    )
    BEGIN
    -- 查询所有省份id
         DECLARE done INT DEFAULT 0;  
         DECLARE cur_province_ids CURSOR FOR SELECT distinct subject_id FROM shop_subject_user_relation;
         DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;  
      
    
     -- 本班次累计域名
    OPEN cur_province_ids; 
    province_ids: LOOP  
    FETCH cur_province_ids INTO province_id;
      IF done = 1 THEN -- 循环结束
            LEAVE province_ids; 
      ELSE
     SELECT
    
          count(*) INTO domain_count
            FROM
                shop_work_order
            where url <>''    group by url;
    -- 本班次累计URL
     SELECT
    
          count(*) INTO url_count
            FROM
                shop_work_order sp
            where url <>''   group by url;
    -- 上班次累计域名
     SELECT
    
          count(*) INTO last_domain_count
            FROM
                shop_work_order
            where url <>''   group by url;
    -- 上班次累计URL
     SELECT
    
          count(*) INTO last_url_count
            FROM
                shop_work_order
            where url <>''   group by url;
    END IF;
    END LOOP province_ids;
    CLOSE cur_province_ids;
    END
    
     
    -- 调用
    call proc_get_province_count_info('1','2','2',@d1,@d2,@d3,@d4);
    SELECT @d1,@d2,@d3,@d4;
    

      

  • 相关阅读:
    [Codeforces 140C] New Year Snowmen
    [Codeforces Round511C] Enlarge GCD
    [BZOJ 1251] 序列终结者
    [NOIP 2016] 愤怒的小鸟
    [POJ 1860] Currency Exchange
    [ZJOI 2006] 书架
    [NOIP 2010] 引入入城
    [NOI 2014] 起床困难综合征
    用C语言实现中文到unicode码的转换
    strdup与strndup
  • 原文地址:https://www.cnblogs.com/liushisaonian/p/10758086.html
Copyright © 2020-2023  润新知