假设表分别为 data、data_1
假设数据如下
data
------------------------------------------
id gid title
1 1 aaaa
2 1 bbbb
3 1 cccc
4 2 dddd
5 1 eeee
------------------------------------------
data_1
------------------------------------------
id gid title
1 1 aaaa
2 2 bbbb
3 1 cccc
4 2 dddd
5 1 eeee
------------------------------------------
统计一个表的sql语句是 select count(id) as num from data where gid='1'
该怎么写才能一次统计出这两个表中,gid为1的数据各有多少条呢?
我这样写好象不对
select
count(data.id) as num1,
count(data_1.id) as num2
from data, data_1
where
data.gid=data_1.gid &&
data.gid='1'