SQL查询计算所有子论坛主题和帖子

时间:2017-06-18 14:20:09

标签: mysql sql

我需要将帖子组织成简单的论坛结构。每个帖子都有title,description,post_id和parent_post_id。 parent_post_id = -1的帖子是根顶级论坛。

Forum 1
  - Topic 1
    - Post 1
    - Post 2
Forum 2
  - Topic 2
    - Post 3
    - Post 4

如何计算论坛1,论坛2等的所有嵌套帖子?

到目前为止,我有以下查询

select forum.title, count(comment.post_id) as count from post as forum
  left outer join post as topic on topic.parent_post_id = forum.post_id
  left outer join post as comment on comment.parent_post_id = topic.post_id
  where forum.parent_post_id = -1
  group by forum.title

但它会返回错误的结果。

1 个答案:

答案 0 :(得分:1)

试试这个

public boolean isInversionModeEnabled() {
    boolean isInversionEnabled =  false;
    int accessibilityEnabled = 0;
    try {
        accessibilityEnabled = Settings.Secure.getInt(this.getContentResolver(),
                android.provider.Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
    } catch (SettingNotFoundException e) {
        Log.d(TAG, "Error finding setting ACCESSIBILITY_DISPLAY_INVERSION_ENABLED: " + e.getMessage());
        Log.d(TAG, "Checking negative color enabled status");
        final String SEM_HIGH_CONTRAST = "high_contrast";
        accessibilityEnabled = Settings.System.getInt(getContentResolver(), SEM_HIGH_CONTRAST, 0);
    }
    if (accessibilityEnabled == 1) {
        Log.d(TAG, "inversion  or negative colour is enabled");
        isInversionEnabled = true;
    } else {
        Log.d(TAG, "inversion  or negative colour is disabled");
    }
    return isInversionEnabled;

}