我有3个表的层次结构。
我需要一个查询,它返回顶部表中的所有条目,并统计该层次结构底部的条目。
例子:
table paragraph has columns : id_paragraph
table sentence has columns : id_sentence, id_paragraph
table word has columns : id_word, id_sentence, font, color
输出示例:
id_paragraph, sentence_count, word_count, word_count_no_font, word_count_font_present, word_count_no_color, word_count_color_present
1, 10, 100, 20, 80, 25, 75
2, 20, 200, 40, 160, 50, 150
id_段落=1,有10个句子,这些句子中的单词和=100,这个段落中的这些单词的总和,其中字体为空的这个段落中的这些单词的总和=20,这个段落中的这些句子中的单词的总和如果这个段落中的颜色是空的,这些单词的总和=25,本段中这些句子中颜色不为空的单词之和=75。
我看到了“left join”和“groupby”如何给我一个2 deep层次结构的解决方案。我试着扭
SQL JOIN 3 TABLES WITH COUNT AND GROUP BY CLAUSE