MySQL:来自多个表的最大日期列

时间:2011-03-06 06:29:56

标签: mysql

我有4张不同的牌桌;每个人都有自己独立的DATETIME。在1个查询中获取MAX的所有日期的MySQL查询是什么?

t1: DATE_TIME
t2: DATE_TIME
t3: DATE_TIME
t4: DATE_TIME

期望的结果

---------------------------------------------------------
| max_t1_date | max_t2_date | max_t3_date | max_t4_date |
---------------------------------------------------------

3 个答案:

答案 0 :(得分:2)

为这只猫皮肤涂抹的方法很多......

SELECT max( t1.a ) AS max_table1date, 
       max( t2.a ) AS max_table2date, 
       max( t3.a ) AS max_table3date
  FROM table1 t1, 
       table2 t2, 
       table3 t3

答案 1 :(得分:1)

我使用MySQL语法已经有一段时间了,目前我无法尝试这一点,但这应该有效:

SELECT
  (SELECT MAX(date_time) FROM t1) AS max_t1_date,
  (SELECT MAX(date_time) FROM t2) AS max_t2_date,
  (SELECT MAX(date_time) FROM t3) AS max_t3_date,
  (SELECT MAX(date_time) FROM t4) AS max_t4_date

答案 2 :(得分:1)

SELECT t1.MaxDate max_t1_date,
  t2.MaxDate max_t2_date,
  t3.MaxDate max_t3_date,
  t4.MaxDate max_t4_date
FROM (SELECT MAX(DATE_TIME) MaxDate  FROM t1) t1
  (SELECT MAX(DATE_TIME) MaxDate  FROM t2) t2,
  (SELECT MAX(DATE_TIME) MaxDate  FROM t3) t3,
  (SELECT MAX(DATE_TIME) MaxDate  FROM t4) t4