How to make aggregations with slick

前端 未结 1 749
悲哀的现实
悲哀的现实 2020-12-29 04:44

I want to force slick to create queries like

select max(price) from coffees where ... 

But slick\'s documentation doesn\'t help

         


        
相关标签:
1条回答
  • 2020-12-29 05:24

    As far as I can tell is the first one simply

    Query(Coffees.map(_.price).max).first
    

    And the second one

    val maxQuery = Coffees
      .groupBy { _.name }
      .map { case (name, c) =>
        name -> c.map(_.price).max
      }
    
    maxQuery.list
    

    or

    val maxQuery = for {
      (name, c) <- Coffees groupBy (_.name)
    } yield name -> c.map(_.price).max
    
    maxQuery.list
    
    0 讨论(0)
提交回复
热议问题