尝试查看哪些视频类别“me_id”和“you_id”都观看了:
SELECT c.title, COUNT(*) AS popularity
FROM video v
JOIN user u ON v.user_id = u.id
JOIN v_cat vc ON c.id = vc.vid_id
JOIN cat c ON c.id = vc.cat_id
JOIN u_cat uc ON uc.cat_id = c.id
WHERE uc.user_id = '$me_id'
INTSERSECT
SELECT c.title, COUNT(*) AS popularity
FROM video v
JOIN user u ON v.user_id = u.id
JOIN v_cat vc ON c.id = vc.vid_id
JOIN cat c ON c.id = vc.cat_id
JOIN u_cat uc ON uc.cat_id = c.id
WHERE uc.user_id = '$you_id'
GROUP BY c.title
ORDER BY uc.id DESC LIMIT 0, 10
我正在使用PHP / MYSQL的任何想法?
答案 0 :(得分:7)
答案 1 :(得分:0)
JOIN JOIN,这是有效的语法吗?
答案 2 :(得分:0)
FROM video v JOIN JOIN v_cat vc ON c.id = vc.vid_id
在上面这行你必须使用加入一次..
答案 3 :(得分:0)
我在你的第一个选择中看到两个连续的JOIN关键字,但没有任何错误信息,这将很难调试。
答案 4 :(得分:0)
而不是INTERSECT,你可以使用关键词UNION或UNION ALL,这基本上会做交叉选择。见http://dev.mysql.com/doc/refman/5.0/en/union.html