简体   繁体   English

我的SQL合并行

[英]My Sql merging rows

How can I query merge rows which has same dates and get rid of null 我如何查询具有相同日期的合并行并摆脱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

to this 对此

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

One approach to getting the specified resultset, is using a GROUP BY and aggregate functions: 获取指定结果集的一种方法是使用GROUP BY和聚合函数:

SELECT t.Date
     , MAX(t.Long) AS `Long`
     , MAX(t.Short) AS `Short`
  FROM mytable t
 GROUP
    BY t.Date
SELECT `date`, MAX(`long`) `long`, MAX(short) short
FROM yourtable
GROUP BY `date`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM