我有两个表,我需要为条件获取这些表的计数?表 1:“tbl_comment”表2:“tbl_group_comment”都有一些共同的列,这些列是用户login_id,这是查询:$param="(SELECT COUNT(*) FROM tbl_comment as t2 WHERE login_id=1) as commentCount, (SELECT COUNT(*) FROM tbl_group_comment as t3 WHERE login_id=1) as commentCount";$table="`tbl_comment` t2 join `tbl_group_comment`";$save['value']=$this->Common_model->common_join($param,$table);这个不起作用,但是如果我更改第二个并保持它,因为它会给我每个表的值,我想得到两个计数的总和?commentCountcommentCount1关于此事,是否有任何具体条款?
1 回答
梦里花落0921
TA贡献1772条经验 获得超6个赞
试试这个:
select sum(comment_count + group_count) from
((SELECT COUNT(*) as comment_count FROM tbl_comment WHERE login_id=1) A,
(SELECT COUNT(*) as group_count FROM tbl_group_comment WHERE login_id=1)B
);
- 1 回答
- 0 关注
- 65 浏览
添加回答
举报
0/150
提交
取消