在MYSQL中比较两列不同的表

时间:2014-06-25 12:06:59

标签: mysql

我有2个表,Books_courseBooks_count。当我触发时出现问题。一旦Books_count更新,它就会检查books_course表中的值15。它比较两者,如果值超过它将打印一条消息

代码:

create trigger alarm after update on books_status 

for each row begin 
  update table1 
    set count=new.count where book_id=new.book_id; 

   declare cnt1 , cnt2; 

   cnt1= select count from books_status; 
   cnt2 =select mini from books_course;

   if (cnt1 > cnt2 ) then 
      echo " fine"; 
   else 
      echo " order more books";

给出以下错误消息..

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=select Books_status.count; cnt2= select Books_course.mini; if (cnt1 > cnt2 ) th' at line 1

1 个答案:

答案 0 :(得分:0)

* ERROR 1064(42000):你的SQL语法有错误**意味着你的mysql语句有问题。

编辑:通常在语句中为额外的空格触发错误。所以试着再过一次,避开空间。请检查此link