if语句使用INSERT作为then子句(MYSQL)

时间:2016-02-04 09:23:48

标签: mysql if-statement

我正在制作一个有条件的插页,但我制作了一个。

条件是这样的

if(select count(*) from employee < 3, insert into employee (name) values ("lisa");

2 个答案:

答案 0 :(得分:1)

您可以尝试这样:

SET some_var = (select count(*) from employee);

if(some_var < 3) then
    insert into employee (name) values ("lisa");
end if

或喜欢

SELECT COUNT(*) AS count into @some_var FROM employee;
if(@some_var < 3) then
    insert into employee (name) values ("lisa");
end if;

答案 1 :(得分:1)

试试这个:

insert into employee(name)
    select 'lisa'
   where (select count(*) from employee) < 3;