Aggregation query

17 views
Skip to first unread message

Gustavo Ramos­

unread,
Feb 13, 2017, 8:01:52 AM2/13/17
to ScalaQuery
Hi all,

How can I make a query like this with slick?

select count(value), sum(value) from tableA;

Thanks,
--
Gustavo R. Almeida

Richard Dallaway

unread,
Feb 13, 2017, 10:57:25 AM2/13/17
to scala...@googlegroups.com
The way I tend to do that is to use the “group by true” trick to get access to query and run aggregations on it:

val q = tableA.groupBy(_ => true).map { case (key, query) => (query.length, query.map(_.value).sum) }

The SQL will be something like:

select count(1), sum(value) from tableA group by true

Anyone have a nicer/better way?
Richard

--

---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/CAAn8MC6vUmuOuOS8VFuqkig-CquZJ%2BxUhcoWSwF%2BdNEYwbQ9YQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages