按两个用户的相同列值对匹配项进行排序
我想按与其他用户的匹配程度对用户兴趣进行排序。视觉示例:
此图像显示此数据:
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
]
...
由于 Swimming
、Birds
、Cats
、 [...] 是共同利益。
我使用 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论