像这样:select count(*) from table where id = 2 group by all name我试了一下,好像不支持啊 如果
select name, count(*) from table where id = 2 group by name
这样的话那些id 不等于2的 name是不能select出来的
select name, count(*) from table where id = 2 group by name
这样的话那些id 不等于2的 name是不能select出来的
类似这样:name count(*)a 0
b 6
c 10
declare cnt int;
declare name1 varchar(80);
select count(*),name from table where id != 2 into cnt,name1;
if cnt = 0 then
select name1,cnt;
end if;
BEGIN END$$DELIMITER ;