gpt4 book ai didi

mysql - 创建一个触发器以计算记录数

转载 作者:行者123 更新时间:2023-11-29 22:02:23 24 4
gpt4 key购买 nike

我的表与“图书”相关,我想在特定列中的特定条件中找到多少条记录

{DELIMITER $$
CREATE TRIGGER No_of_Publisher_year After Insert ON Books FOR EACH ROW Set @Count_NO=@Count_NO + New.Copyright Begin
SELECT Count(@Count_NO) AS 'No_of_publisher_in_year_2007' FROM Books WHERE Copyright=2007;

END; $$
DELIMITER ;}


我收到一个错误:


  1064-您的SQL语法有误;检查与您的MySQL服务器版本对应的手册以获取正确的语法,以在第2行的'SELECT Count(@Count_NO)AS'No_of_publisher_in_year_2007'FROM Books WHERE Copyr'附近使用

最佳答案

您需要像下面修改触发器主体

CREATE TRIGGER No_of_Publisher_year 
After Insert ON Books
FOR EACH ROW
Begin
Set @Count_NO := @Count_NO + New.Copyright;
SELECT Count(*) AS 'No_of_publisher_in_year_2007'
FROM Books WHERE Copyright=2007;
END;

关于mysql - 创建一个触发器以计算记录数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32499035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com