我有以下输出:
root@localhost [~]# mysql -e "SELECT TABLE_ROWS from information_schema.Tables where TABLE_SCHEMA= 'testdb' && TABLE_NAME = 'requests';"
+------------+
| TABLE_ROWS |
+------------+
| 9566846 |
+------------+
root@localhost [~]# mysql -e "select count(*) from testdb.requests where created_at like '2012%';"
+----------+
| count(*) |
+----------+
| 301438 |
+----------+
root@localhost [~]# mysql -e "select count(*) from testdb.requests where created_at like '2013%';"
+----------+
| count(*) |
+----------+
| 24917 |
+----------+
如何更好,使用 mysql 请求对一个请求执行相同的操作以获得新的输出,例如
+------------------+-----------------------+
| year | count(*) |
+------------------+-----------------------+
| 2009 | 1066268 |
| 2010 | 6799553 |
| 2011 | 1374685 |
| 2012 | 301438 |
| 2013 | 24917 |
| total | 9566846 |
+------------------+-----------------------+
提前谢谢你, Evgheni