MYSQL事件IF然后运行查询

时间:2014-08-08 04:09:36

标签: mysql events if-statement

这样做的正确方法是什么?尝试过很多东西并在网上搜索

CREATE EVENT myevent
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 DAYS
DO
  BEGIN


SELECT CASE WHEN funded IS NULL OR funded = '' 
   THEN INSERT INTO mytable1 (`id`, `to`) VALUES (NULL, 'admin')
   ELSE 
FROM mytable2 WHERE id='$id';



  END

2 个答案:

答案 0 :(得分:0)

试试这个

   DECLARE xFounded varchar(10);

  SELECT funded into xFounded  FROM mytable2 WHERE id='$id';

  if xFounded  is null or xFounded  ='' then

   INSERT INTO mytable1 (`id`, `to`) VALUES (NULL, 'admin');
   ELSE 
  // Do Else Part Here

  end if;

答案 1 :(得分:0)

这可能是最有利的方式。

insert into mytable1 (`id`, `to`) VALUES (NULL, 'admin') on duplicate key update id=LAST_INSERT_ID(id), to=to;
select LAST_INSERT_ID();