我有 4 张桌子ACCOUNTS_TABLE
, LINKS_TABLE
, GROUPS_TABLE
,KEYS_TABLE
我需要得到all accounts details
哪个是 acct_typexx
和count of Links, groups& keywords
. 我已经尝试过这个查询,但它给出了所有count as 0
SELECT
acc.acct_id, acc.acct_type, count(link.id) as link_count, link.account,
groups.camp_id, count(groups.id) as group_count, count(keyword.key_id) as key_count
FROM ".ACCOUNTS_TABLE." as acc
LEFT JOIN ".LINKS_TABLE." as link ON link.account=acc.acct_id AND acct_type='xx'
LEFT JOIN ".GROUPS_TABLE." as groups ON groups.camp_id=link.id
LEFT JOIN ".KEYS_TABLE." as keyword ON keyword.camp_id=link.id
GROUP BY acc.acct_id
我需要的输出应该是这样的
任何人请帮我解决这个问题