Title
t

Tristan Caron

05/17/2018, 2:25 PM
Hello, I'm trying to build a query for
select count(distinct my_column) from my_table where my_other_column = true
I have started the fellowing, but I don't know I can achieve what I would like
MyTable.select {
  MyTable.myOtherColumn.eq(true)
}.withDistinct().count()
Any ideas?
I found this working
MyTable
  .slice(MyTable.myColumn.countDistinct())
  .select {
    MyTable.myOtherColumn.eq(true)
  }.first()
  .let {
    it[MyTable.myColumn.countDistinct()]
  }
`
👍 1
t

tapac

05/17/2018, 3:40 PM
you even can write
first()[MyTable.myColumn.countDistinct()]
without
let
MyTable.run {
    slice(myColumn.countDistinct()).
    select { myOtherColumn eq true }.
    first()[myColumn.countDistinct()]
}
t

Tristan Caron

05/18/2018, 6:04 AM
This is true 😀