我有两个表,我需要获取这些表的条件计数?
表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);
这个不起作用,但是如果我更改第二个commentCount
并将其保持commentCount1
它会给我每个表的值,我想得到两个计数的总和?
这件事有什么具体条款吗?
试试这个:
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
);