公司需求是 给段sql查询语句 然后使用shell脚本去执行 设置任务计划 现在的问题就是里面的时间有重复 如何在脚本中去重 而且查询出来 结果是一行数据 如何在脚本中分成几行和几列
#!/bin/sh
TIMESTAMP=`date +%Y%m%d%H%M`
txt=/txt/${TIMESTAMP}.txt
zone=`date -d yesterday +%Y-%m-%d%`
zon=`date +%Y-%m-%d%`
uniq=`sort ${txt} |uniq`
HOST=127.0.0.1
USER=root
PASS=rainbow123
Port=3307
QUERY=`mysql -h$HOST -u$USER -P$Port -p$PASS << EOF
SELECT left(CREATEtime,10) time,count(id_user) user,count(DISTINCT id_user) id_item
FROM iptv_hd.daily_flow_clear24
where CREATEtime > '${zone}' and CREATEtime < '${zon}'
GROUP BY left(CREATEtime,10)
ORDER BY left(CREATEtime,10);
SELECT left(CREATEtime,10),count(DISTINCT id_user) FROM iptv_hd.user_info where CREATEtime > '${zone}' and CREATEtime < '${zon}'
GROUP BY left(CREATEtime,10)
ORDER BY left(CREATEtime,10);
SELECT left(ctime,10),count(id_user),count(DISTINCT id_user) FROM iptv_hd.user_history WHERE ctime > '${zone}' and ctime < '${zon}'
GROUP BY left(ctime,10)
ORDER BY left(ctime,10);
SELECT count(DISTINCT id_user) FROM iptv_hd.daily_flow_clear24 WHERE createtime > '${zone}' and createtime < '${zon}'; -- 脨要录脫脧庐前脌录频脛只卤拢脕20脤脢SELECT count(DISTINCT id_user) FROM iptv_hd.user_list WHERE dtime > '${zone}' and dtime < '${zon}';
SELECT sum(curtime)/3600 from iptv_hd.user_history WHERE ctime > '${zone}' and ctime < '${zon}';
SELECT left(ctime,10),COUNT(DISTINCT id_item) FROM iptv_hd.user_history where ctime > '${zone}' and ctime < '${zon}'
GROUP BY left(ctime,10)
ORDER BY left(ctime,10);
exit
EOF`
echo $QUERY $uniq >>${txt}
现在执行的结果是
如何分成
各位大神谁有好的办法!!!!!!!!!!11
编辑回复