/*
UPDATE dati0917 dt
INNER JOIN
ygh_user u ON dt.idcards=u.ID_CARD_NUM
SET
dt.app_phone = u.LOGIN_NAME;
*/
#select length(csfz) from hzbz;
#select LENGTH(cert_no) from weixin;
#select cert_no from weixin where LENGTH(cert_no)>18;
#SELECT count(0) as hznum from hzbz;
#SELECT count(0) as wxnum from weixin;
#SELECT count(0) as 51num from wuyi_card;
#SELECT count(0) as appnum from ygh;
#數據清理
#delete from wuyi_card where length(wuyi_card_no)=0;
#update weixin set cert_no=trim(cert_no);
#update hzbz set csfz=trim(csfz);
#update wuyi_card set cert_no=trim(cert_no);
#update ygh set ID_CARD_NUM=trim(ID_CARD_NUM);
#查詢不正常身份證
#select cert_no as wx_sfz from weixin where LENGTH(cert_no)<>18 and LENGTH(cert_no)<>15;
#select csfz as hzbz_sfz from hzbz where LENGTH(csfz)<>18 and LENGTH(csfz)<>15;
#select cert_no as 51_sfz from wuyi_card where LENGTH(cert_no)<>18 and LENGTH(cert_no)<>15 and wuyi_card_no is not null;
#select ID_CARD_NUM as app_sfz from ygh where LENGTH(ID_CARD_NUM)<>18 and LENGTH(ID_CARD_NUM)<>15;
#查出重複數據
#select cert_no as wx_sfz from weixin where cert_no in (select cert_no from weixin group by cert_no having count(cert_no)>1);
#select csfz as hzbz_sfz from hzbz where csfz in (select csfz from hzbz group by csfz having count(csfz)>1);
#select cert_no as 51_sfz from wuyi_card where cert_no in (select cert_no from wuyi_card group by cert_no having count(cert_no)>1);
#select ID_CARD_NUM as app_sfz from ygh where ID_CARD_NUM in (select ID_CARD_NUM from ygh group by ID_CARD_NUM having count(ID_CARD_NUM)>1);
#刪除不正常身份證
#delete from weixin where LENGTH(cert_no)<>18 and LENGTH(cert_no)<>15;
#delete from hzbz where LENGTH(csfz)<>18 and LENGTH(csfz)<>15;
#delete from wuyi_card where LENGTH(cert_no)<>18 and LENGTH(cert_no)<>15;
#delete from ygh where LENGTH(ID_CARD_NUM)<>18 and LENGTH(ID_CARD_NUM)<>15;
#刪除重複數據,多執行幾次
/*
DELETE FROM ygh
WHERE id IN
(SELECT id FROM (SELECT id FROM ygh GROUP BY ID_CARD_NUM HAVING count(*) > 1)e);
*/
#進行標識
#51工會卡認證
#update hzbz set wuyika='YES' WHERE csfz IN (select csfz from (select hzbz.csfz FROM hzbz,wuyi_card where hzbz.csfz=wuyi_card.cert_no) a);
#update hzbz set weixin='YES' WHERE csfz IN (select csfz from (select hzbz.csfz FROM hzbz,weixin where hzbz.csfz=weixin.cert_no) a);
#update hzbz set app='YES' WHERE csfz IN (select csfz from (select hzbz.csfz FROM hzbz,ygh where hzbz.csfz=ygh.ID_CARD_NUM) a);
#SELECT count(0) as 51RZ from hzbz where wuyika='YES';
#SELECT count(0) as WXRZ from hzbz where weixin='YES';
#SELECT count(0) as APPRZ from hzbz where app='YES';
#SELECT count(0) as ALLRZ from hzbz where app='YES' AND wuyika='YES' AND weixin='YES';
#按產業和區導出
/*
select DISTINCT(cxtbh) from hzbz;
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='財貿';
select * from hzbz where cxtbh='文衛';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cxtbh='海曙區';
select * from hzbz where cdwm='寧波市海曙區段塘街道洞橋社區';
*/
#update hzbz0527 set wuyika='YES' WHERE csfz IN (select csfz from (select hzbz0527.csfz FROM hzbz0527,wuyi_card where hzbz0527.csfz=wuyi_card.cert_no) a);
#update hzbz0527 set weixin='YES' WHERE csfz IN (select csfz from (select hzbz0527.csfz FROM hzbz0527,weixin0527 where hzbz0527.csfz=weixin0527.cert_no) a);
#update hzbz0527 set app='YES' WHERE csfz IN (select csfz from (select hzbz0527.csfz FROM hzbz0527,ygh where hzbz0527.csfz=ygh.ID_CARD_NUM) a);
#去除奇怪的空格
#update hzbz0527 set csfz=replace(csfz,' ','');
#update hzbz0527 set remark=null;
#標識錯誤身份證號
#update hzbz0527 set remark='身份證格式錯誤' where LENGTH(csfz)<>18 and LENGTH(csfz)<>15;
#標識重複身份證號
/*
update hzbz0527 set remark='身份證重複' where csfz in (
select a.hzbz_sfz from
(
select csfz as hzbz_sfz from hzbz0527 where csfz in (select csfz from hzbz0527 group by csfz having count(csfz)>1)
) a);
*/