shell习题

回复 收藏

公司需求是  给段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}

现在执行的结果是

QQ截图20180705121329.png

如何分成

QQ截图20180705121525.png

各位大神谁有好的办法!!!!!!!!!!11

2018-07-05 12:15 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: