给定以下实体类和带有相关表的postgres数据库:
case class Statistics(name: String,
measure: Long,
datetime: Timestamp = new Timestamp(System.currentTimeMillis))
如何构造一个Squeryl聚合查询,该查询返回每天或每周的度量计数或其累计值,基本上导致SQL语句类似于:
select count(*), date_trunc('day',datetime) from stats
group by date_trunc('day',datetime);
select sum(*), date_trunc('day',datetime) from stats
group by date_trunc('day',datetime);
使用无法从Squeryl直接访问的postgres'date_trunc函数 .
1 回答
可以使用自定义函数映射生成所需的查询:
然后可以在实际查询中使用它,例如: