==========================================
分数据处理地计算有外出人员家庭小汽车数量
select SJCLD,sum(NJYYXQCJL) from
(select
distinct SJCLD,TCDXMC, NJYYXQCJL
from A03A a
inner join
(select
TCDXDM
from A03A
group by TCDXDM
having min(SFLKBXZ6GYJYS)=1) b
on
a.TCDXDM=b.TCDXDM)
group by SJCLD
===========================================
有外出人员,小汽车合计
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
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.TCDXDM asc, a.SFLKBXZ6GYJYS asc
从调查对象代码提取9位处理地:
update a03a set SJCLD=SUBSTRING(TCDXDM FROM 1 FOR 9)
根据是否离开6个月、姓名排序
select
a.SFLKBXZ6GYJYS,
a.TCDXMC,
a.SJCLD,
a.TCDXDM,
a.PCQDM,
a.PCXQDM,
a.HBM,
a.YDSBSBM,
a.PCQMC,
a.PCXQMC,
a.HZXM,
a.HZDHJSFZBXZ,
a.ZHCYYBHJJSHLWYTDRGYJR,
a.NJYYXQCJL,
a.NJYYMTCDPCJL,
a.NJYYMYRSQJT,
a.NJYYKTJB,
a.NJYYDBXGJT,
a.NJYYDNJT,
a.RYDNSFSGHLW,
a.NJYYCSDSJJT,
a.RYCSDSJTGSMFSJSDSJMYXDS,
a.RYCSDSJTGSMFSJSDSJMWX,
a.RYCSDSJTGSMFSJSDSJMQT,
a.NJZYSJYJB,
a.ZYSJZYJBSGHLW,
a.NJ2016NSFYGHLWGW,
a.NJ2016NMSFWJDLKFPH,
a.BHCYBH,
a.XB,
a.NLZS,
a.HYZK,
a.SJYCD,
a.SFZXXS,
a.A2016NCSNYSCHGLSJYDST,
a.CSDNYHYLBZY,
a.CSDNYHYLBCY,
a.A2016NSFZBHYWCSNY30TYS,
a.SFSGNYZYJSPX,
a.SFCSFNHY,
a.NL60ZSJYSZZNSFQBWCBXZ6GYJYS,
a.UUID,
a.DZM,
a.REPORTPERIOD
from A03A a
order by a.TCDXDM asc, a.SFLKBXZ6GYJYS asc
select
a.SFLKBXZ6GYJYS,
a.TCDXMC,
a.SJCLD,
a.TCDXDM,
a.PCQDM,
a.PCXQDM,
a.HBM,
a.YDSBSBM,
a.HZXM,
a.HZDHJSFZBXZ,
a.ZHCYYBHJJSHLWYTDRGYJR,
a.NJYYXQCJL,
a.NJYYMTCDPCJL,
a.RYDNSFSG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