2

我有两张桌子说tableA和tableB。两个表都有文件说 pointA 和 pointB。我需要一个查询来查找pointA 和pointB 列中的最高值和最低值。

 tableA
 idA    pointA
 1        20
 2        12
 3        41
 4        8     


 tableB
 idB    pointB
 1        24
 2        74
 3        2
 4        16    

我想得到这样的结果

 HIGHEST     LOWEST
    74         2      
4

3 回答 3

4

尝试:

SELECT MAX(point) as HIGHEST, MIN(point) as LOWEST
FROM
  (SELECT pointA as point FROM tableA
   UNION
   SELECT pointB as point FROM tableB) t
于 2012-04-10T11:09:50.900 回答
1
select max(pointB) AS result from tableB
union
select min(pointA) AS result from tableA
于 2012-04-10T11:07:31.810 回答
1
SELECT MAX(high) AS highest
     , MIN(low)  AS lowest
FROM
  ( SELECT MAX(pointA) AS high
         , MIN(pointA) AS low
    FROM tableA
  UNION ALL
    SELECT MAX(pointB) 
         , MIN(pointB) 
    FROM tableB
  ) AS tmp
于 2012-04-10T11:12:34.907 回答