我想强制Slick创建类似于查询的内容
但是Slick的文档没有帮助。
由于 q1-q4 并非查询语句,因此我无法获取结果,但可以在其他查询语句中使用它们。
这个陈述。
尝试使用以下方式解决
如何生成这样的查询?
select max(price) from coffees where ...
但是Slick的文档没有帮助。
val q = Coffees.map(_.price) //this is query Query[Coffees.type, ...]
val q1 = q.min // this is Column[Option[Double]]
val q2 = q.max
val q3 = q.sum
val q4 = q.avg
由于 q1-q4 并非查询语句,因此我无法获取结果,但可以在其他查询语句中使用它们。
这个陈述。
for {
coffee <- Coffees
} yield coffee.price.max
生成正确的查询,但已过时(会生成警告:“ColumnExtensionMethods类中的max方法已过时:请使用Query.max代替”)。 如何在没有警告的情况下生成这样的查询?
另一个问题是按组进行聚合:
"select name, max(price) from coffees group by name"
尝试使用以下方式解决
for {
coffee <- Coffees
} yield (coffee.name, coffee.price.max)).groupBy(x => x._1)
生成的
select x2.x3, x2.x3, x2.x4 from (select x5."COF_NAME" as x3, max(x5."PRICE") as x4 from "coffees" x5) x2 group by x2.x3
这会导致明显的数据库错误
column "x5.COF_NAME" must appear in the GROUP BY clause or be used in an aggregate function
如何生成这样的查询?
.first
替代.list.head
,如果我没记错的话。 - user500592