假设我有如下表:
UserActions
UserId INT
ActionDate TIMESTAMP
Description TEXT
保存用户执行某些操作的日期。如果我想获得每个用户执行的最后一个操作,我将不得不在 SQL 中执行以下操作:
SELECT *
FROM UserActions,
(
SELECT ua.UserId,
max(ua.ActionDate) AS lastActionDate
FROM UserActions ua
GROUP BY ua.UserId
) AS lastActionDateWithUserId
WHERE UserActions.UserId = lastActionDateWithUserId.UserId
AND UserActions.ActionDate = lastActionDateWithUserId.lastActionDate
现在,假设我已经在 scalaquery 0.9.5 中为 UserActions 设置了一个表结构,例如:
case class UserAction(userId:Int,actionDate:Timestamp,description:String)
object UserActions extends BasicTable[UserAction]("UserActions"){
def userId = column[Int]("UserId")
def actionDate = column[Timestamp]("ActionDate")
def description = column[String]("Description")
def * = userId ~ actionDate ~ description <> (UserAction, UserAction.unapply _)
}
我的问题是:在 ScalaQuery/SLICK 我如何执行这样的查询?