select b."Id", b."TotalThreads", t.cnt from "Boards" b join (select "BoardId", count(*) cnt from "Threads" group by "BoardId") t on t."BoardId" = b."Id" where (select count(*) from "Boards" sb where sb."ParentBoardId" = b."Id") = 0 and b."TotalThreads" != t.cnt;
select b."Id", b."TotalThreads", sb.total, t.cnt, sb.total + t.cnt from "Boards" b join (select "ParentBoardId", sum("TotalThreads") total from "Boards" group by "ParentBoardId") sb on sb."ParentBoardId" = b."Id" join (select "BoardId", count(*) cnt from "Threads" group by "BoardId") t on t."BoardId" = b."Id" where b."TotalThreads" != sb.total+t.cnt;
