如何从两个以上的表中获取最大值

问题描述:

我有两个表,其中表 B 的列名作为值存储在表 A 中.我需要从表 B 中获取列的最大值.你能帮我实现这个吗..

I have two tables where the column names of table B gets stored as values in table A. I need to fetch max value of columns from table B. Could you please help in acheiving this..

表A结构如下

|身份证 |姓名|

|1 |ABC |

|2 |XYZ |

表 B 的列名称为ABC"和XYZ".我坚持从表 B 中获取最多 ABC 和 XYZ 列.任何帮助将不胜感激.

table B has column names as 'ABC' and 'XYZ'. I'm stuck to fetch max of columns ABC and XYZ from table B. Any help would be of highly appreciated.

也许你可以先联合两个表,然后计算最大值.喜欢:

Maybe you could, first, union both tables, and then calculate the maximum values. like:

SELECT max(ABC), max(XYZ) FROM(select * from table_a联合所有从 table_b 中选择 *) 表;

SELECT max(ABC), max(XYZ) FROM( select * from table_a UNION ALL select * from table_b ) table;