表decla_regularInfo,其中一些字段,
id ,
declarCycle 年度,
declarYear 报告年度
DeclarType 申报类型
dataStatus 完成状态 (1待提交、2待审核、3审核通过、4待修改);
怎么一条SQL实现这样形式
解释一下:其中
审核通过就是 完成状态 3,
已申报人数就是 完成状态 2 3 4
select t2.declarCycle as 年度,
t2.declarYear as 报告年度,
t2.DeclarType as 申报类型,
count(1) as 应申报人数,
(select count(1)
from decla_regularInfo t1
where t1.declarCycle = t2.declarCycle
and t1.DeclarType = t2.DeclarType
and t1.declaryear = t2.declaryear
and t1.dataStatus = '1') as 审核通过,
(select count(1)
from decla_regularInfo t3
where t3.declarCycle = t2.declarCycle
and t3.DeclarType = t2.DeclarType
and t3.declaryear = t2.declaryear
and t3.dataStatus in ('2', '3', '4')) as 已申报人数
from decla_regularInfo t2
group by t2.declaryear, t2.declarCycle, t2.DeclarType
order by declarCycle, DeclarType;
select
id,
declarYear,
declarCycle,d
eclarType,
count(datastatus) as '应申报人数',
(select count(datastatus) from declar_regularInfo where datastatus in (2,3,4)) as '已申报人数',
(select count(datastatus) from declar_regularInfo where datastatus = 3 ) as '审核通过'
from
declar_regularInfo
group by id,declarYear,declarCycle,declarType;
,结构就是这样,应该不是正确的
不知道是不是这个意思
select t2.declarCycle as 年度,
t2.declarYear as 报告年度,
t2.DeclarType as 申报类型,
count(1) as 应申报人数,
(select count(1)
from decla_regularInfo t1
where t1.declarCycle = t2.declarCycle
and t1.DeclarType = t2.DeclarType
and t1.declaryear = t2.declaryear
and t1.dataStatus = '1') as 审核通过,
(select count(1)
from decla_regularInfo t3
where t3.declarCycle = t2.declarCycle
and t3.DeclarType = t2.DeclarType
and t3.declaryear = t2.declaryear
and t3.dataStatus in ('2', '3', '4')) as 已申报人数
from decla_regularInfo t2
group by t2.declaryear, t2.declarCycle, t2.DeclarType
order by declarCycle, DeclarType;
select
id,
declarYear,
declarCycle,d
eclarType,
count(datastatus) as '应申报人数',
(select count(datastatus) from declar_regularInfo where datastatus in (2,3,4)) as '已申报人数',
(select count(datastatus) from declar_regularInfo where datastatus = 3 ) as '审核通过'
from
declar_regularInfo
group by id,declarYear,declarCycle,declarType;