写的脚本记一下
1 12 * * * /bin/sh /home/shaolei/mysql_sql.sh 每天12 点执行
#!/bin/bash
# to call SQL statement at MySQL prompt
mysql -h ip -P 3306 -ubunny -p83OGCufr9 <<EOF
use bunny;
#delete yesterday data
delete from b_building_property_demographic_filter;
#insert into new data
insert into b_building_property_demographic_filter
select * from
(select did as id, bid as buildingPropertyId,counts.demographicTypeId as demographicTypeId,counts.demographicId as demographicId,
labercount as deviceCount,source,bcityid as cityid,buildcount as buildingDeviceCount,
round((labercount*100/buildcount)) as accouning,
round((labercount/buildcount)*100/(laber/citycount)) as tgi,updateTime
from
(select demo.id did,build.id as bid,buildingPropertyId, build.cityid as bcityid,IF(xinchaoid is null ,0,1) as source,
demographicTypeId,demographicId,build.deviceCount buildcount,
demo.DeviceCount labercount,citycount,updateTime
from
b_building_property build ,
b_building_property_demographic demo ,
(select cityid,sum(devicecount) citycount
from b_building_property
GROUP BY cityid
) city
where build.id=demo.buildingPropertyId
and city.cityid=build.cityid
) counts,
(select cityid,sum(bb.devicecount) as laber,demographicId
from b_building_property aa ,b_building_property_demographic bb
where aa.id=bb.buildingPropertyId
group by cityid,demographicId
) labercouns
where labercouns.cityid=counts.bcityid
and counts.demographicId=labercouns.demographicId
order by id ) hhhh;
EOF
exit;