按两个用户的相同列值对匹配项进行排序

发布于 2025-01-11 16:21:12 字数 1387 浏览 0 评论 0原文

我想按与其他用户的匹配程度对用户兴趣进行排序。视觉示例:

“在此处输入图像描述”

此图像显示此数据:

array:42 [▼
  0 => array:3 [▼
    "id" => 82
    "title" => "Travel"
    "status" => 1
  ]
  1 => array:3 [▼
    "id" => 75
    "title" => "Bubble Tea"
    "status" => 1
  ]

...

但应显示此:

array:42 [▼
  0 => array:3 [▼
    "id" => 82
    "title" => "Swimming"
    "status" => 1
  ]
  1 => array:3 [▼
    "id" => 75
    "title" => "Birds"
    "status" => 1
  ]

...

由于 SwimmingBirdsCats、 [...] 是共同利益。

我使用 status = -1 表示不喜欢,使用 status = 1 表示喜欢。我有以下两个表:

interests [ id , title ]

interests_status [ id,interest_id, user_id, status ]

SELECT `i`.`id`, `i`.`title`, `a`.`status` 
FROM `interests` as `i` 
INNER JOIN `interests_status` as `a` on `a`.`interest_id` = `i`.`id` 
INNER JOIN `interests_status` as `b` on `b`.`interest_id` = `i`.`id` 
WHERE `a`.`user_id` = 10 
GROUP BY `i`.`id` 
ORDER BY b.user_id = 11 AND a.status = b.status DESC

我怎样才能优先显示我与该用户的所有匹配(喜欢和不喜欢)的结果?我尝试第二次连接到同一个表来引用我(用户 ID 11),但这不起作用。

I want to sort user interests by matches with other users. Visual example:

enter image description here

This image shows this data:

array:42 [▼
  0 => array:3 [▼
    "id" => 82
    "title" => "Travel"
    "status" => 1
  ]
  1 => array:3 [▼
    "id" => 75
    "title" => "Bubble Tea"
    "status" => 1
  ]

...

But should show this:

array:42 [▼
  0 => array:3 [▼
    "id" => 82
    "title" => "Swimming"
    "status" => 1
  ]
  1 => array:3 [▼
    "id" => 75
    "title" => "Birds"
    "status" => 1
  ]

...

Since Swimming, Birds, Cats, [...] are mutual interests.

I use status = -1 for a dislike and status = 1 for a like. I have the following two tables:

interests [ id , title ]

interests_status [ id, interest_id, user_id, status ]

SELECT `i`.`id`, `i`.`title`, `a`.`status` 
FROM `interests` as `i` 
INNER JOIN `interests_status` as `a` on `a`.`interest_id` = `i`.`id` 
INNER JOIN `interests_status` as `b` on `b`.`interest_id` = `i`.`id` 
WHERE `a`.`user_id` = 10 
GROUP BY `i`.`id` 
ORDER BY b.user_id = 11 AND a.status = b.status DESC

How can I priotize the results that all my matches (both likes and dislikes) with this user are displayed first? I tried a second join to the same table to reference to me (user id 11) but this doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文