多表查询同一表不同值mysql

zpjtge22  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(281)

我需要一些mysql的帮助,因为我是一个新手。我需要计算来自不同数据库的不同表的值,并将它们全部放在一个表中,然后为每个计数创建一个索引,例如:

_______________________
|           |           |
|  Indexes  |   Counts  |
|___________|___________|
|           |           |
|  Index 1  |  Count 1  |
|___________|___________|
|           |           |
|  Index 2  |  Count 2  |
|___________|___________|
|           |           |
|  Index 3  |  Count 3  |
|___________|___________|
|           |           |
|  Index 4  |  Count 4  |
|___________|___________|

但就像我现在正在做的(与工会)它看起来像:

___________
|           |
|  Counts   |
|___________|
|           |
|  Count 1  |
|___________|
|           |
|  Count 2  |
|___________|
|           |
|  Count 3  |
|___________|
|           |
|  Count 4  |
|___________|

你知道吗?提前谢谢。
编辑:
我现在使用的代码是

SELECT COUNT(*) AS "db1" FROM `db1`.`tb1`
UNION
SELECT COUNT(*) AS "db2" FROM `db2`.`tb2`
o7jaxewo

o7jaxewo1#

试试这个。

SELECT "db1.tb1" as "INDEXES", COUNT(*) AS "COUNTS" FROM `db1`.`tb1`
UNION
SELECT "db2.tb2" as "INDEXES", COUNT(*) AS "COUNTS" FROM `db2`.`tb2`

相关问题