我有这个mySQL表:
eventBus
是否可以通过网址对条目进行分组,并在不创建新表的情况下删除一个mySQL调用中的重复项?
理想的表格:
id | url | origin | categroy | date
1 | url.com/1 | US | news | 2015-10-01 12:39:19
2 | url.com/1 | | | 2015-10-01 13:59:34
3 | url.com/2 | CN | news | 2015-09-01 12:45:26
4 | url.com/3 | | | 2015-08-12 09:10:10
5 | url.com/3 | US | news | 2015-09-14 04:56:36
6 | url.com/4 | US | | 2015-09-09 12:12:09
我是初学者,我尝试使用失败的php脚本来解决这个问题。我想有一个相当简单的SQL答案,但我无法在Stackoverflow上找到一个简单的答案。
非常感谢!
答案 0 :(得分:0)
尝试此查询
SELECT id, url,
SUBSTRING_INDEX(GROUP_CONCAT(origin ORDER BY date DESC),',',1) as origin_value,
SUBSTRING_INDEX(GROUP_CONCAT(category ORDER BY date DESC),',',1) as category_value,
SUBSTRING_INDEX(GROUP_CONCAT(date ORDER BY date DESC),',',1) as date_value FROM tablename
GROUP BY url
ORDER BY url,date DESC