我有一个 html 表格,我想在其中显示cht_name
,count_hoh
和count_members
. 我可以得到计数的结果,count_hoh
因为我有相同的字段cht_id
onhousehold_tbl
和主表 on tbl_cht_members
。我在获取具有相同字段但没有字段count_members
的表的计数时遇到了麻烦,我可以在其中直接获取相同的计数。我只是通过.tbl_household_members
household_tbl
cht_id
count_hoh
household_connector_id
SELECT cht_id as cht, name,
(SELECT household_connector_id as hoh,
COUNT(*)
FROM household_tbl
WHERE cht_id = cht) as count_hoh,
(SELECT COUNT(*)
FROM tbl_household_members
WHERE household_connector_id = hoh) as count_members
FROM tbl_cht_members
GROUP BY cht_id