基本上我想要
Select * from x
JOIN y
on x.id = y.x_id
where y.tag_id in (1, 2, 3, 4) order by [the amount of hits of y.tag_id]
所以
说y可以是:
id | x_id | tag_id
1 | 55 | 2
2 | 55 | 3
3 | 66 | 1
我想让记录x.id = 55排序在x.id = 66之上.55有2次点击(2和3)而66只有一次点击
答案 0 :(得分:1)
您可以在子查询中找到每个x_id的命中数,将其与X表连接,并按计算的数量对结果进行排序。
Select * from x
JOIN y
on x.id = y.x_id
inner join (
select x_id, count(*) cnt
from y
group x_id
) t on x.id = t.x_id
where y.tag_id in (1, 2, 3, 4)
order by t.cnt desc;
答案 1 :(得分:1)
计算与传递的accuracy = accuracy_score(y_test, y_pred)
Traceback (most recent call last):
File "<ipython-input-263-232dbb7449ea>", line 1, in <module>
accuracy = accuracy_score(y_test, y_pred)
File "C:\Anaconda3\lib\site-packages\sklearn\metrics\classification.py",
line 172, in accuracy_score
y_type, y_true, y_pred = _check_targets(y_true, y_pred)
File "C:\Anaconda3\lib\site-packages\sklearn\metrics\classification.py",
line 82, in _check_targets
"".format(type_true, type_pred))
ValueError: Can't handle mix of multilabel-indicator and continuous-
multioutput
匹配的x_id
并在tag_id
中使用
Order by
在计数时应用过滤器很重要,因为我们需要计算匹配的SELECT *
FROM x
JOIN y
ON x.id = y.x_id
JOIN (SELECT x_id,
Count(*) hit_cnt
FROM y
WHERE y.tag_id IN ( 1, 2, 3, 4 )
GROUP BY x_id) ct
ON ct.x_id = y.x_id
ORDER BY hit_cnt DESC
的{{1}}