==============================================
从调查对象代码提取9位处理地:****************************************************
update a03 set SJCLD=SUBSTRING(TCDXDM FROM 1 FOR 9)
===================================================
乡镇,有外出人员家庭数量,人数,小汽车数量,摩托车,热水器,空调,电冰箱,电脑,电视,电话
select SJCLD as XZ, count(*) as fams, sum(ZHCYYBHJJSHLWYTDRGYJR) as pers,
sum(NJYYXQCJL) as cars,
sum(NJYYMTCDPCJL) as mots,
sum(NJYYMYRSQJT) as heas,
sum(NJYYKTJB) as airs,
sum(NJYYDBXGJT) as refs,
sum(NJYYDNJT) as pcs,
sum(NJYYCSDSJJT) tvs,
sum(NJZYSJYJB) tels
from
(select
distinct SJCLD,b.TCDXDM, ZHCYYBHJJSHLWYTDRGYJR,
a.NJYYXQCJL,
a.NJYYMTCDPCJL,
a.NJYYMYRSQJT,
a.NJYYKTJB,
a.NJYYDBXGJT,
a.NJYYDNJT,
a.NJYYCSDSJJT,
a.NJZYSJYJB
from A03 a
inner join
(select
TCDXDM
from A03
group by TCDXDM
having min(SFLKBXZ6GYJYS)=1) b
on
a.TCDXDM=b.TCDXDM)
group by SJCLD
==========================================
分组到乡镇,有外出人员家庭数量,人数,小汽车数量 ***********************************
select SJCLD as XZ, count(*) as fams, sum(ZHCYYBHJJSHLWYTDRGYJR) as pers, sum(NJYYXQCJL) as cars from
(select
distinct SJCLD,b.TCDXDM, ZHCYYBHJJSHLWYTDRGYJR, NJYYXQCJL
from A03 a
inner join
(select
TCDXDM
from A03
group by TCDXDM
having min(SFLKBXZ6GYJYS)=1) b
on
a.TCDXDM=b.TCDXDM)
group by SJCLD
==============================================
乡镇代码,调查对象代码,户人数,小汽车数量
select
distinct SJCLD,b.TCDXDM, ZHCYYBHJJSHLWYTDRGYJR, NJYYXQCJL
from A03 a
inner join
(select
TCDXDM
from A03
group by TCDXDM
having min(SFLKBXZ6GYJYS)=2) b
on
a.TCDXDM=b.TCDXDM
===========================================
有外出人员,小汽车合计
select sum(NJYYXQCJL) from
(select
distinct TCDXMC, NJYYXQCJL
from A03A a
inner join
(select
TCDXDM
from A03A
group by TCDXDM
having min(SFLKBXZ6GYJYS)=1) b
on
a.TCDXDM=b.TCDXDM)
==========================================
有外出人员,分户小汽车数量
select
TCDXMC,SFLKBXZ6GYJYS,NJYYXQCJL
from A03A a
inner join
(select
TCDXDM
from A03A
group by TCDXDM
having min(SFLKBXZ6GYJYS)=1) b
on
a.TCDXDM=b.TCDXDM
___________________________________________
有外出的户编码,分户总人数
select
count(*) as rens, min(a.SFLKBXZ6GYJYS) as waichu1, max(a.SFLKBXZ6GYJYS) as waichu2,
a.TCDXMC
from A03 a
group by a.TCDXMC
having min(a.SFLKBXZ6GYJYS)=1
___________________________________________
有外出的户编码:
select
min(a.SFLKBXZ6GYJYS) as waichu1, max(a.SFLKBXZ6GYJYS) as waichu2,
a.TCDXDM
from A03A a
group by a.TCDXDM
having min(a.SFLKBXZ6GYJYS)=1
改良:
select
min(a.SFLKBXZ6GYJYS) as waichu1,
a.TCDXDM
from A03A a
group by a.TCDXDM
having min(a.SFLKBXZ6GYJYS)=1
改良:
select
a.TCDXDM
from A03A a
group by a.TCDXDM
having min(a.SFLKBXZ6GYJYS)=1
==============================================
无外出的户编码:
select
a.TCDXDM
from A03A a
group by a.TCDXDM
having min(a.SFLKBXZ6GYJYS)='2'
==============================================
显示外出情况最大、最小代码及户编码:
select
min(a.SFLKBXZ6GYJYS) as waichu1, max(a.SFLKBXZ6GYJYS) as waichu2,
a.TCDXDM
from A03A a
group by a.TCDXDM
显示有外出的代码:
select
count(a.TCDXDM) as ifwaichu,
a.TCDXDM
from A03A a
where a.SFLKBXZ6GYJYS='1'
group by a.TCDXDM
仅显示离开6个月以上的对象代码:
select
a.TCDXDM
from A03A a
where a.SFLKBXZ6GYJYS='1'
group by a.TCDXDM
记录一致的只显示一条:
select
distinct a.TCDXMC,
a.SFLKBXZ6GYJYS,
a.SJCLD,
a.TCDXDM,
a.PCQDM,
a.NJYYXQCJL,
a.NJYYCSDSJJT
from A03A a
order by a.TCDX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