【问题标题】:Kotlin-Exposed : How to select a max timestampKotlin-Exposed:如何选择最大时间戳
【发布时间】:2021-06-30 23:59:38
【问题描述】:

此处是 Jetbrains Exposed Framework 的新手。我有一个包含 3 个字段的 oracle 表。

ID TIMESTAMP FLAG
1234 May1 12AM Y
1234 May1 3PM N

我想查询 FLAG = Y 的最大时间戳行,但我不知道该怎么做。

Employee.run {
    val results = select {(id eq employeeId) and (flag eq "Y")}
    // If no row with Flag = Y then I guess I can just return if results are empty          
    !results.empty()
}

我不确定如何检查其中的最大时间戳。

【问题讨论】:

    标签: kotlin-exposed


    【解决方案1】:

    最终找到了一种方法来做到这一点。我确信 Kotlin 和 Expose 都有更好的方法。

    fun Person.hasFlag(employeeId: String): Boolean {
        return transaction(db) {
            Employee.run {
                val results = slice(id, timeStamp, flag).select {(id eq employeeId)}.groupBy(id, timeStamp, flag)
                if (results.empty()) false else results.map {
                    Pair(it[timeStamp], it[flag])
                }.maxByOrNull { m -> m.first }?.second == "Y"
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-02
      • 2016-06-10
      • 2021-10-31
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 2016-03-23
      • 2013-06-22
      相关资源
      最近更新 更多