Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 把最后一排排排好_Sql_Postgresql_Scala_Slick - Fatal编程技术网

Sql 把最后一排排排好

Sql 把最后一排排排好,sql,postgresql,scala,slick,Sql,Postgresql,Scala,Slick,我有一个PostgreSQL表 信息: |id | phone | message | login | ----------------------------------- * |1 | 85543422 | Hello! | User1 | |2 | 85543422 | i love | User2 | -----------------------------------* 我需要按电话值(85543422)筛选表,并从最后一行获取用户名。 现在我有了一个方法,允

我有一个PostgreSQL表

信息:

 |id  |  phone | message | login |
-----------------------------------
* |1   | 85543422 | Hello!  | User1 |
  |2   | 85543422 | i love  | User2 |
-----------------------------------*
我需要按电话值(85543422)筛选表,并从最后一行获取用户名。 现在我有了一个方法,允许您从第一行提取用户名

//return "User1"
    def getUserByPhone():String = {  
          val query = outgoing.filter(_.phone === "85543422").map(_.login).result.headOption
          val result = Await.result(db.run(query), Duration.Inf)
          if (result.value.isEmpty) return "None"
          result.value.get
      }
帮助实现从最后一行中删除用户名的方法。
我需要获取“User2”

您可以按id desc排序以获取最后一行的用户名

乙二醇

val query=outgoing.filter(u.phone==“85543422”)
.sortBy(u.id.desc)
.map(u.login).result.headOption

Waw!这是个好主意!好的,我试试看。