下面的查询获取了一个名为的变量中的值result
result=`mysql --user=root --password=password1 deployment --host=localhost -Ns -e "SELECT DATE_FORMAT(LAST_DAY(url_timestamp), '%M %Y') month, COUNT(url_timestamp) counter FROM mytable WHERE status='PRODUCTION' and url_timestamp >= NOW() - INTERVAL 1 YEAR GROUP BY month, LAST_DAY(url_timestamp) ORDER BY LAST_DAY(url_timestamp);"`
echo $result
输出:
November 2019 43 December 2019 556 January 2020 111 February 2020 221 .... November 2020 98
注意:在 sql 客户端中可见的 SQL 查询的输出格式良好。但是,当分配给 shell 变量时,行格式会丢失。
我的预期输出是:
November 2019 43
December 2019 556
January 2020 111
February 2020 221
....
....
November 2020 98
你能建议一下吗?