Scala slick执行复杂的SQL查询

时间:2016-07-18 20:20:01

标签: mysql scala orm playframework-2.0 slick

我是一个新的灵活用户,我在创建一个光滑的查询时遇到了麻烦。 我需要使用slick执行此SQL查询:

SELECT COUNT(dd.definition_id) accuracy, d.id, d.subject_id, d.creator_id, d.active
FROM definition_detail dd
INNER JOIN definition d
ON dd.definition_id=d.id
WHERE dd.value_id IN (1,2,3)
GROUP BY dd.definition_id;

我试图自己做,但我设法只创建了这个:

db.run((definition join definitionDetailDAO.definitionDetail on ((d, dd) => d.id === dd.definition_id))
        .map{
          case (d, dd) => (d, dd)
        }.filter(_._2.value_id inSet valuesSeq)
        .map{
          case (d, dd) => (d.id, d.subject_id, d.creator_id, d.active)
        }.result)

这与此查询相对应:

SELECT d.id, d.subject_id, d.creator_id, d.active
FROM definition_detail dd
INNER JOIN definition d
ON dd.definition_id=d.id
WHERE dd.value_id IN (1,2,3);

任何人都可以帮我学习吗?

P.S。我正在使用这种依赖:

libraryDependencies += "com.typesafe.play" %% "play-slick" % "2.0.0"

libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "2.0.0"

1 个答案:

答案 0 :(得分:1)

Slick的组与SQL相比,这里解释了http://slick.lightbend.com/doc/3.1.1/sql-to-slick.html

获取值而不聚合使用.max / .min或.head