数据库有两个字段,isFinish和isRepeat 值都是0 和1 来判断是否完成和是否重复

isFinish和isRepeat 值都是0 和1 来判断是否完成和是否重复,现在我想查找数据库中
完成,未完成,重复,所有数据的数据量怎么查出来,可以用一条sql语句吗,如果是
分为四次单独查询效率太低,求解。。。。
意思就是 select 完成的数量,未完成的数量,重复的数量,所有数量 from table
这个样子,一次获取这四个数据。而不是分成四次查询获得数据

用union可以实现
select count(*) from table where isfinish = 0
union
select count(*) from table where isfinish = -1
union
select count(*) from table where isrepeat = 0
union
select count(*) from table where isrepeat = -1

可用case...when语法区分各种条件

行转列。
例如:isFinish=0表示完成,1表示未完成;isRepeat=0表示不重复,1表示重复:
select
(case when t.isFinish=0 then t.isFinish else '' end) as "完成的数据",
(case when t.isFinish=1 then t.isFinish else '' end) as "未完成的数据",
(case when t.isRepeat=1 then t.isRepeat else '' end) as "重复的数据"
from table t;

参考自:MySQL行转列、列转行常用函数用法介绍 http://www.data.5helpyou.com/article388.html