如何将恶意查询转换为Mysql?

时间:2013-10-30 11:24:17

标签: mysql mongodb scala

我发现了一个用Rogue写的代码

Rogue is a type-safe internal Scala DSL for constructing and executing find and modify commands against MongoDB in the Lift web framework

我发现用scala编写的代码是查询数据

我希望将该代码转换为mysql查询

def getBlogScore(word: String, blog: String): Long = Keyword.where(_.word eqs word).and(_.blog eqs blog)
    .fetch.map(_.score._1)
    .reduceLeftOption(_ + _).getOrElse(0)

给我一​​些想法!

1 个答案:

答案 0 :(得分:1)

由于.reduceLeft( _ + _ )会将所有分数加在一起,这可能就是您所需要的:

SELECT SUM(score)
FROM keyword
WHERE blog = 'blog'
AND word = 'word'