我有 2 张桌子:
STEP
id
value
SCALE
id
s1
s2
s3
s4
s5
s6
现在 step.id 是 scale.s1、scale.s2、scale.s3 等的外键我想从 step 中获取 scale.s1-s6 值。我用嵌套选择编写了这个查询。是否可以通过一次选择获得此值?
SELECT (
SELECT step.val FROM step, scale WHERE step.id = scale.s1 AND scale.id = 1) as v1,(
SELECT step.val FROM step,scale WHERE step.id = scale.s2 AND scale.id = 1) as v2, (
SELECT step.val FROM step,scale WHERE step.id = scale.s3 AND scale.id = 1) as v3, (
SELECT step.val FROM step,scale WHERE step.id = scale.s4 AND scale.id = 1) as v4, (
SELECT step.val FROM step,scale WHERE step.id = scale.s5 AND scale.id = 1) as v5, (
SELECT step.val FROM step,scale WHERE step.id = scale.s4 AND scale.id = 1) as v6, (
SELECT step.val FROM step,scale WHERE step.id = scale.s5 AND scale.id = 1) as v7 ;