我有这个架构:
Story
_id
name
Paragraph
_id
text
story_id
( the chapter can start from a specific story and
a specific paragraph and
ends with a specific story and specific paragraph).
Chapter
_id
name
start_story_id
start_paragraph_id( first paragraph id in the story which _id == start_story_id)
end_story_id
end_paragraph_id ( last paragraph id in the story which _id == end_story_id)
我想知道特定段落在哪一章。我有故事 ID 和段落 ID。这是我到目前为止所尝试的,它给出了正确的结果:
SELECT MIN(_id)
FROM chapter
WHERE ( start_story_id = @param_story_id
AND start_paragraph_id >= @param_parahgraph_id )
OR ( end_story_id = @param_story_id
AND end_paragraph_id >= @param_parahgraph_id )
OR ( @param_story_id >= start_story_id
AND @param_story_id <= end_story_id )