问题SQL Server: How to Join to first row显示了在SQL中实现的方法。我正在使用光滑的3.0,有三个表:
class ABRelationTable(tag: Tag) extends Table[(Int, Int)](tag, "A_B_RELATION") {
def aId = column[Int]("A_ID")
def bId = column[Int]("B_ID")
def * = (aId, bId)
}
class ACRelationTable(tag: Tag) extends Table[(Int, Int)](tag, "A_C_RELATION") {
def aId = column[Int]("A_ID")
def cId = column[Int]("C_ID")
def * = (aId, cId)
}
class ATable(tag: Tag) extends Table[(Int, String)](tag, "A") {
def id = column[Int]("ID")
def data = column[String]("DATA")
def * = (aId)
}
我想要的是给bId
获取对象A和ONE cId
。例如:
表A:
ID DATA
==================
1 101
2 102
3 103
表A_B_RELATION
A_ID B_ID
=================
1 1
2 1
3 2
表A_C_RELATION
A_ID C_ID
=================
1 1
2 1
2 2
给定bId = 1
,结果可以是:
A_ID DATA C_ID
=====================
1 101 1
2 102 1
谢谢!
答案 0 :(得分:0)
The following will be your query .
val query = A.join(A_C_RELATION).on(_.ID === _. A_ID) .join(A_B_RELATION).on(_.ID === _. A_ID).filter(_.B_ID ===)
Where A , A_C_RELATION , A_B_RELATION are tablequery of respective tables .
Refer here for more examples.