根据相关性查找数据,然后从 diff 域中取出 2 个结果

发布于 2024-09-15 09:16:03 字数 1429 浏览 10 评论 0原文

我的数据库中有很多域名,例如

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏夜暖风 2024-09-22 09:16:03

MySQL 没有分析函数,而您需要使用分析函数来获取每个分组的两个条目。另一个痛苦是“www”。使定位第二个周期变得复杂......

使用:

SELECT x.url
  FROM (SELECT t.url,
               t.teet,
               t.html,
               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

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:

SELECT x.url
  FROM (SELECT t.url,
               t.teet,
               t.html,
               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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文