我有一个mysql命令: - “mysql -uroot -pxxx -e”使用dbname; select * from tablename;“| wc -l” 其输出为“23”,我有多个tablename,我需要数字,我想在这样的文件中重定位这些数字:
"table1 = 23"
"table2 = 25"
"table3 = 45"
我尝试了这个SQL查询: -
SELECT 'table1' AS table_label, COUNT(*) AS table_size FROM table1
UNION SELECT 'table2', COUNT(*) FROM table2
UNION SELECT 'table3', COUNT(*) FROM table3
但它给我这样的结果: -
+---------------------+------------+
| table_label | table_size |
+---------------------+------------+
| 2016-03-17 12:10:14 | 132 |
| 2016-03-17 12:10:37 | 33 |
+---------------------+------------+
但我希望表格如下: -
+---------------------+------------+
| table_label | table_size |
+---------------------+------------+
| table1 | 132 |
| table2 | 33 |
+---------------------+------------+