作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 SLICK 中编写查询时遇到问题
这是我对 MySql 数据库的请求:
SELECT * FROM readings AS r
JOIN parameters AS p
LEFT JOIN sensorvalues AS sv ON sv.parameter_id=p.id AND sv.reading_id=r.id
val q = for{
Join(p,sv) <- Parameters leftJoin SensorValues on (_.id is sv.parameter_id)
r <- Readings if sv.reading_id is r.id
} yield(r,p,sv)
wrong number of parameters; expected = 2
constructor cannot be instantiated to expected type; found : models.Join required: (models.Parameters.type, models.SensorValues.type)
import scala.slick.lifted.Join
现在它看起来像是常规的innerJoin,因为它使用WHERE 而不是在ON 之后放置和。
select x2.id, x2.platform_id, x2.date, x3.x4, x3.x5, x3.x6, x7.x8, x7.x9, x7.x10, x7.x11 from (select x12.id as x4, x12.name as x5, x12.units as x6 from parameters x12) x3 left outer join (select x13.id as x8, x13.reading_id as x9, x13.parameter_id as x10, x13.value as x11 from sensorValues x13) x7 on x3.x4 = x7.x10, readings x2 where true and (x7.x9 = x2.id)
val readings = for {
all <-Readings join Parameters leftJoin SensorValues on (_._2.id is _.parameter_id) if(all._1._1.id === all._2.reading_id)
} yield (all._1._1,all._1._2,all._2)
SELECT
x2.x3,
x2.x4,
x2.x5,
x2.x6,
x2.x7,
x2.x8,
x9.x10,
x9.x11,
x9.x12,
x9.x13
FROM
(
SELECT
x14.x15 AS x3,
x14.x16 AS x4,
x14.x17 AS x5,
x18.x19 AS x6,
x18.x20 AS x7,
x18.x21 AS x8
FROM
(
SELECT
x22.`id` AS x15,
x22.`platform_id` AS x16,
x22.`date` AS x17
FROM
`readings` x22
)x14
INNER JOIN(
SELECT
x23.`id` AS x19,
x23.`name` AS x20,
x23.`units` AS x21
FROM
`parameters` x23
)x18
)x2
LEFT OUTER JOIN(
SELECT
x24.`id` AS x10,
x24.`reading_id` AS x11,
x24.`parameter_id` AS x12,
x24.`value` AS x13
FROM
`sensorValues` x24
)x9 ON x2.x6 = x9.x12
WHERE
x2.x3 = x9.x11
WHERE
我需要
AND
.我应该用什么来提及这种情况,或者没有光滑的功能?
最佳答案
编辑
OP 正在寻找连接 2 个表对象的条件链。
这应该编译:
val q = for{
r <- Readings
Join(p,s) <- Params leftJoin Sensors on (
(a,b)=> (a.id is b.parameter_id) && (b.reading_id is r.id)
)
} yield(r,p,s)
val q = for{
Join(p,s) <- Params leftJoin Sensors on (_.id is s.parameter_id)
r <- Readings if s.reading_id is r.id
} yield(r,p,s)
val result =
q.list.map{ case(r,p,s)=>
SomeCaseClass(r,p,s)
}
关于scala - 如何将 AND 添加到连接 SLICK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13405246/
我是一名优秀的程序员,十分优秀!