求一条查询语句的写法。
表abc1 字段 id vlue1 表 abc2 字段 id value2
aaa 3 aaa 7
aaa 4 aaa 8
aaa 5 aaa 5
bbb 2 bbb 1
ccc 1 bbb 4
ccc 2 ccc 5
现在我需要查询结果 这样的 id count(abc1) count(abc2)
aaa 3 3
目的是:返回id在abc1和abc2中都有2条以上数据的项,并且把数据项多少统计出来。看结果只有 aaa满足,但我不知道存储怎么去写!求高人解决!
------解决方案--------------------select x.id,x.count1,y.count2
from (
select id,count(*) as count1 from a group by id having count*)> 2
) as x,(
select id,count(*) as count1 from b group by id having count*)> 2
) as y
where x.id=y.id
------解决方案-------------------- Select
A.id,
A.abc1count,
B.abc2count
From
(Select id, Count(id) As abc1count From abc1 Group By id Having Count(id) > 2) A
Inner Join
(Select id, Count(id) As abc2count From abc2 Group By id Having Count(id) > 2) B
On A.id = B.id
------解决方案--------------------select a.id,count(a.vlue1),count(b.value2) from abc1 a inner join abc2 on a.id = b.id
where count(a.vlue1)> 2 and count(b.value2) > 2
group by a.id
------解决方案--------------------create table abc1
(
id varchar(10),