Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不能使用mycat2.0创建存储过程吗 #2952

Open
z18539749496 opened this issue Jun 17, 2024 · 0 comments
Open

不能使用mycat2.0创建存储过程吗 #2952

z18539749496 opened this issue Jun 17, 2024 · 0 comments

Comments

@z18539749496
Copy link

z18539749496 commented Jun 17, 2024

CREATE PROCEDURE `poly_pay_transaction_max_concurrency`()
BEGIN
		DECLARE currentDate DATE;
    DECLARE endDate DATE;

    -- 获取开始和结束日期
    SELECT MIN(DATE(create_time)), (MAX(DATE(create_time))- INTERVAL 1 DAY) INTO currentDate, endDate
    FROM poly_pay_transaction;

    -- 创建临时表用于存储结果
    CREATE TABLE IF NOT EXISTS poly_pay_transaction_max_concurrency (
        day DATE,
				max_concurrency_time INT,
        max_concurrency INT
    );

    -- 循环计算每一天的活跃商户数
    WHILE currentDate <= endDate DO
				-- 添加条件判断,确保不重复统计已经处理过的日期
        IF NOT EXISTS (SELECT 1 FROM poly_pay_transaction_max_concurrency WHERE day = currentDate)
				THEN
 					INSERT INTO poly_pay_transaction_max_concurrency (day,max_concurrency_time, max_concurrency)
 					SELECT currentDate, DATE_FORMAT(create_time,'%H') '时间节点', COUNT(id) AS count
					FROM poly_pay_transaction
					WHERE DATE_FORMAT(create_time,'%Y-%m-%d') = currentDate
					GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S')
					ORDER BY count DESC
					LIMIT 1;
 				END IF;

        -- 更新日期
        SET currentDate = currentDate + INTERVAL 1 DAY;
    END WHILE;

    -- 选择结果
    SELECT * FROM poly_pay_transaction_max_concurrency;

    -- 删除临时表
    -- DROP TABLE IF EXISTS poly_pay_transaction_max_concurrency;
END;

报错信息:

CREATE PROCEDURE `poly_pay_transaction_max_concurrency`()
BEGIN
		DECLARE currentDate DATE;
    DECLARE endDate DATE;

    -- 获取开始和结束日期
    SELECT MIN(DATE(create_time)), (MAX(DATE(create_time))- INTERVAL 1 DAY) INTO currentDate, endDate
    FROM poly_pay_transaction;

    -- 创建临时表用于存储结果
    CREATE TABLE IF NOT EXISTS poly_pay_transaction_max_concurrency (
        day DATE,
				max_concurrency_time INT,
        max_concurrency INT
    );

    -- 循环计算每一天的活跃商户数
    WHILE currentDate <= endDate DO
				-- 添加条件判断,确保不重复统计已经处理过的日期
        IF NOT EXISTS (SELECT 1 FROM poly_pay_transaction_max_concurrency WHERE day = currentDate)
				THEN
 					INSERT INTO poly_pay_transaction_max_concurrency (day,max_concurrency_time, max_concurrency)
 					SELECT currentDate, DATE_FORMAT(create_time,'%H') '时间节点', COUNT(id) AS count
					FROM poly_pay_transaction
					WHERE DATE_FORMAT(create_time,'%Y-%m-%d') = currentDate
					GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S')
					ORDER BY count DESC
					LIMIT 1
> 0 - com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'IMIT 1', expect END, actual null, pos 1036, line 28, column 14, token EOF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant