1
SlickでCOUNT(DISTINCT ...)を表現する方法は?SlickのCOUNT(DISTINCT ...)
sql"""select formatdatetime("timestamp",'yyyy.MM.dd'), count(distinct "order_id")
from "sales" group by
formatdatetime("timestamp",'yyyy.MM.dd')""".as[(String,Option[Int])]
私はこれを試してみました:
私はこのクエリと同等のものを構築したい
[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'}>]
(私はH2を使用)
:実行時例外をスローval values = sales groupBy { entry =>
formatDatetime(entry.timestamp, datetimeFormat)
} map { case(formattedDatetime, group) =>
(formattedDatetime, group.distinctOn(_.orderId).length.?)
}