带有INSERT as then子句的if语句(MYSQL)

带有INSERT as then子句的if语句(MYSQL),mysql,if-statement,Mysql,If Statement,我正在进行有条件的插入,但在进行插入时遇到问题 情况是这样的 if(select count(*) from employee < 3, insert into employee (name) values ("lisa"); 您可以这样尝试: SET some_var = (select count(*) from employee); if(some_var < 3) then insert into employee (name) values ("lisa");

我正在进行有条件的插入,但在进行插入时遇到问题

情况是这样的

if(select count(*) from employee < 3, insert into employee (name) values ("lisa");
您可以这样尝试:

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;
您可以这样尝试:

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;
试试这个:

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

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