我有以下SQL代码,它完全符合我的要求。我想尝试使用Cypher做同样的事情。
select distances.userid as userid, dist/(sqrt(my.norm)*sqrt(users.norm)) as score
from (select userid,
sum((user.rating)*(ratings.rating)) as dist
from ratings, user
where user.itemid = ratings.itemid
group by userid) as distances,
(select userid, sum((rating)*(rating)) as norm
from ratings
group by userid) as users,
(select sum((rating)*(rating)) as norm
from user) as my
where users.userid = distances.userid
order by score desc
limit 80;
在我的密码图中,用户和项目之间的密码关系“RATES”包含用户评级。 密码节点用户包含用户ID和用户平均评级,在sql中,在ratings.rating中有帮助。
我试图单独实现每个子查询但是遇到麻烦,因为每个子查询似乎都依赖于下一个,我不确定如何链接我的密码查询。
如何在cypher中实现此功能?
编辑-------------------
管理翻译最后一个子查询。
SQL
select sum((rating)*(rating)) as norm
from user
Cypher支架
MATCH (n)-[r:RATES]->(m)
WHERE n.userid = '1'
RETURN sum((toInt(r.rating))*(toInt(r.rating))) as norm
仍然不确定如何在主查询中使用它。
答案 0 :(得分:3)