SQL for NC4


SELECT word1.word_lower,word2.word_lower,word3.word_lower,count(*) cnt
FROM biotext_annotation compound
JOIN biotext_annotation table_1028568911 ON
   compound.pmid = table_1028568911.pmid AND
   compound.section = table_1028568911.section AND
   compound.sentence = table_1028568911.sentence AND
   table_1028568911.first_word_pos = compound.first_word_pos AND
   compound.first_word_pos <= table_1028568911.first_word_pos
JOIN biotext_annotation table_799192222 ON
   compound.pmid = table_799192222.pmid AND
   compound.section = table_799192222.section AND
   compound.sentence = table_799192222.sentence AND
   table_1028568911.last_word_pos = table_799192222.first_word_pos
JOIN biotext_annotation table_1948145843 ON
   compound.pmid = table_1948145843.pmid AND
   compound.section = table_1948145843.section AND
   compound.sentence = table_1948145843.sentence AND
   table_799192222.last_word_pos = table_1948145843.first_word_pos AND
   table_1948145843.last_word_pos = compound.last_word_pos
JOIN biotext_annotation_word word1 on
table_1028568911.word_id = word1.word_id
JOIN biotext_annotation_word word2 on
table_799192222.word_id = word2.word_id
JOIN biotext_annotation_word word3 on
table_1948145843.word_id = word3.word_id
WHERE (compound.layer_id IN (3) 
AND compound.tag_type IN (31)) 
AND (table_1028568911.layer_id IN (1) 
AND table_1028568911.tag_type IN (27, 28, 29, 30)) 
AND (table_799192222.layer_id IN (1) 
AND table_799192222.tag_type IN (27, 28, 29, 30)) 
AND (table_1948145843.layer_id IN (1) 
AND table_1948145843.tag_type IN (27, 28, 29, 30))
AND NOT EXISTS (
   SELECT * 
   FROM biotext_annotation noun_zero
   WHERE noun_zero.pmid = compound.pmid
     AND noun_zero.section = compound.section
     AND noun_zero.sentence = compound.sentence
     AND noun_zero.first_word_pos >= compound.first_word_pos
     AND noun_zero.last_word_pos < table_799192222.first_word_pos
     AND noun_zero.layer_id = 1
     AND noun_zero.tag_type IN (27, 28, 29, 30)
)
group by word1.word_lower,word2.word_lower,word3.word_lower
order by cnt desc
;