簡體   English   中英

MySQL 5.6.21存儲過程SQL錯誤1064

[英]MySQL 5.6.21 Stored procedure SQL error 1064

我有這個查詢,可以正常工作,並給出預期的結果。

SELECT count(*) AS total_unsolved,
    (select count(deadline) from my_table where datediff(deadline, CURTIME()) = 0 and response_time is null) as today_to_solve,
    (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 0 and datediff(deadline, CURTIME()) < 4 and response_time is null) as days_left_1_3,
    (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 3 and datediff(deadline, CURTIME()) < 8 and response_time is null) as days_left_4_7,
    (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 7 and response_time is null) as mt_week,
    (select count(deadline) from my_table where datediff(deadline, CURTIME()) < 0 and datediff(deadline, CURTIME()) > -4 and response_time is null) as overdue_1_3_days,
    (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -3 and datediff(deadline, CURTIME()) > -11 and response_time is null) as overdue_4_10_days,
    (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -10 and datediff(deadline, CURTIME()) > -30 and response_time is null) as overdue_11_30_days,
    (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -30 and response_time is null) as overdue_mt_month,
    (select count(deadline) from my_table where datediff(deadline, response_time) < 0 and response_time is not null) as solved_with_delay  
 from my_table where response_time is null 

在此處輸入圖片說明

我想創建一個過程來顯示給定時間范圍內的結果。 所以我輸入了以下內容:

CREATE PROCEDURE status_in_timerange
     (
        IN   start_date                     TiMESTAMP, 
        IN   close_date                     TiMESTAMP,
        OUT  total_unsolved                 INT,  
        OUT  today_to_solve                 INT, 
        OUT  days_left_1_3                  INT, 
        OUT  days_left_4_7                  INT, 
        OUT  mt_week                        INT, 
        OUT  overdue_1_3_days               INT, 
        OUT  overdue_4_10_days              INT,      
        OUT  overdue_11_30_days             INT,    
        OUT  overdue_mt_month               INT,    
        OUT  solved_with_delay              INT    
     )
BEGIN 

    SELECT count(DATEDIFF(deadline, NOW())) AS total_unsolved,
        (select count(deadline) from my_table where datediff(deadline, CURTIME()) = 0 and response_time is null and ktimestamp BETWEEN start_date and close_date),
        (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 0 and datediff(deadline, CURTIME()) < 4 and response_time is null and ktimestamp BETWEEN start_date and close_date),
        (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 3 and datediff(deadline, CURTIME()) < 8 and response_time is null and ktimestamp BETWEEN start_date and close_date),
        (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 7 and response_time is null and ktimestamp BETWEEN start_date and close_date),
        (select count(deadline) from my_table where datediff(deadline, CURTIME()) < 0 and datediff(deadline, CURTIME()) > -4 and response_time is null and ktimestamp BETWEEN start_date and close_date),
        (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -3 and datediff(deadline, CURTIME()) > -11 and response_time is null and ktimestamp BETWEEN start_date and close_date),
        (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -10 and datediff(deadline, CURTIME()) > -30 and response_time is null and ktimestamp BETWEEN start_date and close_date),
        (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -30 and response_time is null and ktimestamp BETWEEN start_date and close_date),
        (select count(deadline) from my_table where datediff(deadline, response_time) < 0 and response_time is not null and ktimestamp BETWEEN start_date and close_date) 

    INTO   total_unsolved , 
           today_to_solve, 
           days_left_1_3, 
           days_left_4_7, 
           mt_week, 
           overdue_1_3_days ,
           overdue_4_10_days,
           overdue_11_30_days,
           overdue_mt_month,
           solved_with_delay

  FROM my_table WHERE response_time is null and ktimestamp BETWEEN start_date and close_date
END ;

不幸的是,此查詢顯示如下錯誤:

SQL錯誤(1064):您的SQL語法有錯誤; 檢查與您的MySQL服務器版本相對應的手冊以獲取正確的語法,以在第41行的“ END”附近使用

我已經閱讀了相關問題(包括以下內容),這些問題無助於解決問題。

MySQL存儲過程錯誤

MySQL存儲過程錯誤1064

PS select version(); 返回5.6.21

嘗試:

mysql> DELIMITER //

mysql> CREATE PROCEDURE status_in_timerange
    ->      (
    ->         IN   start_date                     TiMESTAMP, 
    ->         IN   close_date                     TiMESTAMP,
    ->         OUT  total_unsolved                 INT,  
    ->         OUT  today_to_solve                 INT, 
    ->         OUT  days_left_1_3                  INT, 
    ->         OUT  days_left_4_7                  INT, 
    ->         OUT  mt_week                        INT, 
    ->         OUT  overdue_1_3_days               INT, 
    ->         OUT  overdue_4_10_days              INT,      
    ->         OUT  overdue_11_30_days             INT,    
    ->         OUT  overdue_mt_month               INT,    
    ->         OUT  solved_with_delay              INT    
    ->      )
    -> BEGIN 
    ->     SELECT count(DATEDIFF(deadline, NOW())) AS total_unsolved,
    ->         (select count(deadline) from my_table where datediff(deadline, CURTIME()) = 0 and response_time is null and ktimestamp BETWEEN start_date and close_date),
    ->         (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 0 and datediff(deadline, CURTIME()) < 4 and response_time is null and ktimestamp BETWEEN start_date and close_date),
    ->         (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 3 and datediff(deadline, CURTIME()) < 8 and response_time is null and ktimestamp BETWEEN start_date and close_date),
    ->         (select count(deadline) from my_table where datediff(deadline, CURTIME()) > 7 and response_time is null and ktimestamp BETWEEN start_date and close_date),
    ->         (select count(deadline) from my_table where datediff(deadline, CURTIME()) < 0 and datediff(deadline, CURTIME()) > -4 and response_time is null and ktimestamp BETWEEN start_date and close_date),
    ->         (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -3 and datediff(deadline, CURTIME()) > -11 and response_time is null and ktimestamp BETWEEN start_date and close_date),
    ->         (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -10 and datediff(deadline, CURTIME()) > -30 and response_time is null and ktimestamp BETWEEN start_date and close_date),
    ->         (select count(deadline) from my_table where datediff(deadline, CURTIME()) < -30 and response_time is null and ktimestamp BETWEEN start_date and close_date),
    ->         (select count(deadline) from my_table where datediff(deadline, response_time) < 0 and response_time is not null and ktimestamp BETWEEN start_date and close_date) 
    ->     INTO   total_unsolved , 
    ->            today_to_solve, 
    ->            days_left_1_3, 
    ->            days_left_4_7, 
    ->            mt_week, 
    ->            overdue_1_3_days ,
    ->            overdue_4_10_days,
    ->            overdue_11_30_days,
    ->            overdue_mt_month,
    ->            solved_with_delay
    ->   FROM my_table
    ->   WHERE response_time is null and
    ->         ktimestamp BETWEEN start_date and close_date;
    -> END//
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM