How can I query merge rows which has same dates and get rid of 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:
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`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.