0

如何查询具有相同日期的合并行并摆脱 null

Date       | Long | Short
2006-07-06 | t1   |
2006-07-06 |      | t2
2006-07-05 | t1   | 
2006-07-05 |      | t2
2006-07-04 | t1   |
2006-07-04 |      | t2
2006-07-03 | t1   | 
2006-07-03 |      | t2

对此

Date       | Long | Short
2006-07-06 | t1   | t2
2006-07-05 | t1   | t2
2006-07-04 | t1   | t2
2006-07-03 | t1   | t2
4

2 回答 2

0

获取指定结果集的一种方法是使用 GROUP BY 和聚合函数:

SELECT t.Date
     , MAX(t.Long) AS `Long`
     , MAX(t.Short) AS `Short`
  FROM mytable t
 GROUP
    BY t.Date
于 2013-07-12T15:12:46.700 回答
-1
SELECT `date`, MAX(`long`) `long`, MAX(short) short
FROM yourtable
GROUP BY `date`
于 2013-07-12T15:11:50.453 回答