Hello, I'm trying to build a query for `select cou...
# exposed
t
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
Copy code
MyTable.select {
  MyTable.myOtherColumn.eq(true)
}.withDistinct().count()
Any ideas?
I found this working
Copy code
MyTable
  .slice(MyTable.myColumn.countDistinct())
  .select {
    MyTable.myOtherColumn.eq(true)
  }.first()
  .let {
    it[MyTable.myColumn.countDistinct()]
  }
`
👍 1
t
you even can write
first()[MyTable.myColumn.countDistinct()]
without
let
Copy code
MyTable.run {
    slice(myColumn.countDistinct()).
    select { myOtherColumn eq true }.
    first()[myColumn.countDistinct()]
}
t
This is true 😀
315 Views