--to count the ddo's records on each district--
select
dist_code,
sum(case when scheme = 'I' then 1 else 0 end) as ICDS,
sum(case when scheme = 'N' then 1 else 0 end) as NMP
from
m_ddo
group by
dist_code
order by
dist_code
--to count the total centres--
select
t1.dist,
t2.description,
sum (case when t1.scheme = 'N' then tot else 0 end) as NMP,
sum (case when t1.scheme = 'I' then tot else 0 end) as ICDS
from
(
select substring(ddo_id,1,2) as dist, scheme, count(*) as tot from m_nmc_icds
group by dist, scheme
order by dist
) t1
left join m_district t2 on t2.code = t1.dist
group by
t1.dist,
t2.description
order by
t1.dist
--To count the ddo's in each districts--
select
d.code,
d.description,
count(y.dist_code)
from
m_district d
left outer join m_ddo y on y.dist_code = d.code
where
d.code::int <= 32
group by
d.code,
d.description
order by
d.code
--statistics report for email--
select
*
from
(
select
coalesce(sum(nmp),0) as nmp,
coalesce(sum(icds),0) as icds
from
(
select
case when substring(e.empid,10,1) = 'N' then count(*) else 0 end as NMP,
case when substring(e.empid,10,1) = 'I' then count(*) else 0 end as ICDS
from
emp_data e
where
to_char(created_on,'yyyy-mm-dd') = '2010-12-14'
group by
substring(e.empid,10,1)
) tl11
) tl12
join
(
select
coalesce(sum(nmp),0) as tnmp,
coalesce(sum(icds),0) as ticds
from
(
select
case when substring(e.empid,10,1) = 'N' then count(*) else 0 end as NMP,
case when substring(e.empid,10,1) = 'I' then count(*) else 0 end as ICDS
from
emp_data e
where
created_on <= '2010-12-14'::date
group by
substring(e.empid,10,1)
) tl21
) tl22 on 1=1
--District wise status report--
select
l1.*,
md.description as dname,
(select count(e1.off_desig) from emp_data e1
where
substring(e1.empid, 1, 2) = dist
and substring(e1.empid, 10, 1) = sch
and e1.off_desig IN ('01','04','05')) as org,
(select count(e1.off_desig) from emp_data e1
where
substring(e1.empid, 1, 2) = dist
and substring(e1.empid, 10, 1) = sch
and e1.off_desig IN ('02','06')) as help1,
(select count(e1.off_desig) from emp_data e1
where
substring(e1.empid, 1, 2) = dist
and substring(e1.empid, 10, 1) = sch
and e1.off_desig IN ('03','07')) as help2,
(select count(id) from m_nmc_icds mc
where
substring(mc.ddo_id, 1, 2) = dist
and mc.scheme = sch) as totcentres
from (
select
substring(eg.empid, 1, 2) as dist,
substring(eg.empid, 10, 1) as sch,
count(distinct centre) centre,
count(*) total,
sum(case when verified is true then 1 else 0 end) as verified,
max(created_on) as last
from
emp_data eg
group by
dist, sch ) as l1
left outer join m_district md on md.code = l1.dist
order by
dname, l1.sch
select
dist_code,
sum(case when scheme = 'I' then 1 else 0 end) as ICDS,
sum(case when scheme = 'N' then 1 else 0 end) as NMP
from
m_ddo
group by
dist_code
order by
dist_code
--to count the total centres--
select
t1.dist,
t2.description,
sum (case when t1.scheme = 'N' then tot else 0 end) as NMP,
sum (case when t1.scheme = 'I' then tot else 0 end) as ICDS
from
(
select substring(ddo_id,1,2) as dist, scheme, count(*) as tot from m_nmc_icds
group by dist, scheme
order by dist
) t1
left join m_district t2 on t2.code = t1.dist
group by
t1.dist,
t2.description
order by
t1.dist
--To count the ddo's in each districts--
select
d.code,
d.description,
count(y.dist_code)
from
m_district d
left outer join m_ddo y on y.dist_code = d.code
where
d.code::int <= 32
group by
d.code,
d.description
order by
d.code
--statistics report for email--
select
*
from
(
select
coalesce(sum(nmp),0) as nmp,
coalesce(sum(icds),0) as icds
from
(
select
case when substring(e.empid,10,1) = 'N' then count(*) else 0 end as NMP,
case when substring(e.empid,10,1) = 'I' then count(*) else 0 end as ICDS
from
emp_data e
where
to_char(created_on,'yyyy-mm-dd') = '2010-12-14'
group by
substring(e.empid,10,1)
) tl11
) tl12
join
(
select
coalesce(sum(nmp),0) as tnmp,
coalesce(sum(icds),0) as ticds
from
(
select
case when substring(e.empid,10,1) = 'N' then count(*) else 0 end as NMP,
case when substring(e.empid,10,1) = 'I' then count(*) else 0 end as ICDS
from
emp_data e
where
created_on <= '2010-12-14'::date
group by
substring(e.empid,10,1)
) tl21
) tl22 on 1=1
--District wise status report--
select
l1.*,
md.description as dname,
(select count(e1.off_desig) from emp_data e1
where
substring(e1.empid, 1, 2) = dist
and substring(e1.empid, 10, 1) = sch
and e1.off_desig IN ('01','04','05')) as org,
(select count(e1.off_desig) from emp_data e1
where
substring(e1.empid, 1, 2) = dist
and substring(e1.empid, 10, 1) = sch
and e1.off_desig IN ('02','06')) as help1,
(select count(e1.off_desig) from emp_data e1
where
substring(e1.empid, 1, 2) = dist
and substring(e1.empid, 10, 1) = sch
and e1.off_desig IN ('03','07')) as help2,
(select count(id) from m_nmc_icds mc
where
substring(mc.ddo_id, 1, 2) = dist
and mc.scheme = sch) as totcentres
from (
select
substring(eg.empid, 1, 2) as dist,
substring(eg.empid, 10, 1) as sch,
count(distinct centre) centre,
count(*) total,
sum(case when verified is true then 1 else 0 end) as verified,
max(created_on) as last
from
emp_data eg
group by
dist, sch ) as l1
left outer join m_district md on md.code = l1.dist
order by
dname, l1.sch
No comments:
Post a Comment