目前有一个数据库格式如下:
id(唯一ID)
网址:http://domain.com/page.html
网址来自同一个域和来自不同的域.
这也需要在一个查询中完成,这样我可以在向最终用户显示数据时使用限制等内容.
数据
1, http://domain.com/about.html
2, http://domain.com/index.html
3, http://anotherdomain.com/index.html
4, http://anotherdomain.com/contact.html
Run Code Online (Sandbox Code Playgroud)
预期输出
(我只想返回每个组的第一个url(首先是对数据进行排序的命令,此示例为"id ASC"),其中组由共享根域的URL组成.)
1, http://domain.com/about.html
3, http://anotherdomain.com/index.html
Run Code Online (Sandbox Code Playgroud)
这应该可行,但在连接表时可能会遇到问题
SELECT REPLACE(REPLACE(SUBSTRING_INDEX(LOWER(table.url), '/', 3), 'www.', ''), 'http://', '') AS 域 从表 按域分组