1
Comment exprimer COUNT (DISTINCT ...) dans Slick?COUNT (DISTINCT ...) dans Slick
Je veux construire un équivalent de cette requête:
sql"""select formatdatetime("timestamp",'yyyy.MM.dd'), count(distinct "order_id")
from "sales" group by
formatdatetime("timestamp",'yyyy.MM.dd')""".as[(String,Option[Int])]
J'ai essayé ceci:
val values = sales groupBy { entry =>
formatDatetime(entry.timestamp, datetimeFormat)
} map { case(formattedDatetime, group) =>
(formattedDatetime, group.distinctOn(_.orderId).length.?)
}
Ce qui génère une exception d'exécution:
[info] slick.SlickTreeException: Cannot convert node to SQL Comprehension
[info] | Path s9._2 : Vector[t2<{s3: Int', s4: java.sql.Timestamp', s5: scala.math.BigDecimal', s6: java.sql.Timestamp', s7: String', s8: String'}>]
(j'utilise H2)