mysql存储过程把一个表里面的数据插入到另一个表里面,要怎么写?

如题所述

BEGIN
    DECLARE total_money DOUBLE;
    SELECT SUM(daymoney) INTO total_money FROM shop;
    INSERT INTO day (totalmoney) VALUES(total_money);
    UPDATE shop SET daymoney = 0.0;
END
-- id、date这些字段你就自己加上去就是了

追问

谢谢,请问 ID 和date 要不要declare?

追答

可以不用啊,比如你要用当前时间你就,INSERT INTO day (date, totalmoney) VALUES(now(), total_money)

追问

在你的回答上,我加了一个ratio后运行报错是为什么?

Procedure execution failed

1172 - Result consisted of more than one row

不好意思没接触过存储过程这一块

温馨提示:答案为网友推荐,仅供参考