Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have EXPERIMENTAL_RUNS (runId), each of which have any number of SENSORS (sensorId) associated with them. With that in mind, I have an RS table to join the two:

==========
RS
==========
runId, sensorId

Thus if the run with runId=1 had sensors with sensorId=1, sensorId=6, sensorId=8 in it, there would be 3 entries in the RS table: (runId=1, sensorId=1) (runId=1, sensorId=6) (runId=1, sensorId=8)

Is this really how I would return all EXPERIMENTAL_RUNS that have sensors {11,13,15}? From what I've read, what I seem to want is a nested hash join... Is this what's going to happen?

SELECT a.runId
FROM rs a, rs b, rs c
WHERE
a.runId=b.runId AND
b.runId=c.runId AND
a.sensorId=11 AND
a.sensorId=13 AND
b.sensorId=15

To clarify, I want to return only the EXPERIMENTAL_RUNS that have sensors 11 AND 13 AND 15.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
879 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming runId, sensorId are unique in the rs table, this will find the runIds that have all 3 sensorIds:

SELECT runId, COUNT(c) ct
FROM rs
WHERE sensorId IN (11, 13, 15)
GROUP BY runId
HAVING ct = 3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...