根据相关性查找数据,然后从 diff 域中取出 2 个结果
我的数据库中有很多域名,例如
www.yahoo.com/duniya.html
www.yahoo.com/hero.html
www.123musiq.com/
www.123musiq.com/home.html
www.123musiq.com/horo.html
www.123musiq.com/yuva.html
www.sensongs.com/
www.sensongs.com/hindi.html
www.sensongs.com/yuva.html
www.sensongs.com/duniya.html
www.sensongs.pk/duniya1.html
我需要对它们进行排序,前 2 个来自 yahoo,然后下 2 个来自 123musiq,然后下 2 个来自 sensongs。 我怎样才能做到这一点?在 mysql 还是 PHP 中? 我知道要获取域名,我需要知道如何从每个域中排序 2?
我正在使用匹配方法
期望输出
www.yahoo.com/duniya.html www.yahoo.com/hero.html www.123musiq.com/ www.123musiq.com/home.html www.sensongs.com/ www.sensongs.com/hindi.html
I Use following Code
SELECT x.url FROM (SELECT t.url, CASE WHEN @domain = SUBSTRING_INDEX(t.url, '/', 1) THEN @rownum := @rownum + 1 ELSE @rownum := 1 END AS rank, @domain := SUBSTRING_INDEX(t.url, '/', 1) FROM URL2 t JOIN (SELECT @rownum := 0, @domain := '') r ORDER BY SUBSTRING_INDEX(t.url, '/', 1)) X WHERE x.rank <= 2 AND MATCH(teet,url,html) AGAINST ('account');
It Showing Error
Query : SELECT x.url FROM (SELECT t.url, CASE WHEN @domain = SUBSTRING_INDEX(t.url, '/', 1) THEN @row... Error Code : 1054 Unknown column 'teet' in 'where clause'
但 Teet 是我的 URL2 表中的一列
I am having so much domain name in my DB, for example
www.yahoo.com/duniya.html
www.yahoo.com/hero.html
www.123musiq.com/
www.123musiq.com/home.html
www.123musiq.com/horo.html
www.123musiq.com/yuva.html
www.sensongs.com/
www.sensongs.com/hindi.html
www.sensongs.com/yuva.html
www.sensongs.com/duniya.html
www.sensongs.pk/duniya1.html
i need to sort them like,first 2 from yahoo,then next 2 from 123musiq then next 2 from sensongs.
how can i do that? in mysql or PHP?
i know to get the domain name,i need to know how to sort 2 from each domain?
i am using match against method
Expecting output
www.yahoo.com/duniya.html www.yahoo.com/hero.html www.123musiq.com/ www.123musiq.com/home.html www.sensongs.com/ www.sensongs.com/hindi.html
I Use following Code
SELECT x.url FROM (SELECT t.url, CASE WHEN @domain = SUBSTRING_INDEX(t.url, '/', 1) THEN @rownum := @rownum + 1 ELSE @rownum := 1 END AS rank, @domain := SUBSTRING_INDEX(t.url, '/', 1) FROM URL2 t JOIN (SELECT @rownum := 0, @domain := '') r ORDER BY SUBSTRING_INDEX(t.url, '/', 1)) X WHERE x.rank <= 2 AND MATCH(teet,url,html) AGAINST ('account');
It Showing Error
Query : SELECT x.url FROM (SELECT t.url, CASE WHEN @domain = SUBSTRING_INDEX(t.url, '/', 1) THEN @row... Error Code : 1054 Unknown column 'teet' in 'where clause'
But Teet is a Column in my URL2 Table
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MySQL 没有分析函数,而您需要使用分析函数来获取每个分组的两个条目。另一个痛苦是“www”。使定位第二个周期变得复杂......
使用:
MySQL doesn't have analytic functions, which is what you'd need to get the two entries per grouping. The other pain is the "www." complicates locating the 2nd period...
Use: