有表a,b ,下面是一些数据
select * from a;
id name namecode ids
1 w 1w 11
2 s 2s 22
3 c 3c 33
4 d 4d 33select * from b;
id name vid ids
1 w 11 11
2 s 22 22
3 c 33 33
4 d 33 33联合查询结果
select * from a,b where a.ids=b.idsid name namecode ids id name vid ids
1 w 1w 11 1 w 11 11
2 s 2s 22 2 s 22 22
3 c 3c 33 3 c 33 33
4 d 4d 33 3 c 33 33
3 c 3c 33 4 d 33 33
4 d 4d 33 4 d 33 33 我想根据b表的vid字段把a 表的数据分组,结果为
select count(a.id),b.vid from a,b where a.ids=b.ids group by b.vid
count(a.id) ids
1 11
1 22
4 33
但是下面才是我想要的结果:
count(a.id) ids
1 11
1 22
2 33
想了很久,都没想出要怎么解决,不知哪位大侠能帮帮我?
select * from a;
id name namecode ids
1 w 1w 11
2 s 2s 22
3 c 3c 33
4 d 4d 33select * from b;
id name vid ids
1 w 11 11
2 s 22 22
3 c 33 33
4 d 33 33联合查询结果
select * from a,b where a.ids=b.idsid name namecode ids id name vid ids
1 w 1w 11 1 w 11 11
2 s 2s 22 2 s 22 22
3 c 3c 33 3 c 33 33
4 d 4d 33 3 c 33 33
3 c 3c 33 4 d 33 33
4 d 4d 33 4 d 33 33 我想根据b表的vid字段把a 表的数据分组,结果为
select count(a.id),b.vid from a,b where a.ids=b.ids group by b.vid
count(a.id) ids
1 11
1 22
4 33
但是下面才是我想要的结果:
count(a.id) ids
1 11
1 22
2 33
想了很久,都没想出要怎么解决,不知哪位大侠能帮帮我?
解决方案 »
- 两个oracle数据库导入和导出问题,急
- ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小 的问题
- ORA-04091: 表 EGIS_ADMIN.RESOURCE_TYPE 发生了变化, 触发器/函数不能读它
- 向[hebo2005]提问:关于rank() row_number() 以及 over()等后面连接 partition by... order by...
- 如何判定当前日期的月份是双月 还是单月?
- 每个汉字在char/nchar/varchar2/nvarchar2中占几位
- 在Oracle9i数据库中能否用create or replace index来创建索引?
- 为什么我在进oms的时候看不到[数据库]目录?但在进入oem却能看到数据库
- 为什么我用刚创建的用户不能登录ORAClE呢?望各位帮忙解答一下
- 关于一个长SQL的优化,有没有大神能提点一下...毫无头绪...
- background 转储区的使用率是 97%。
- ORACLE中建立外码,标识符无效
select * from a;
id name namecode ids
1 w 1w 11
2 s 2s 22
3 c 3c 33
4 d 4d 33select * from b;
id name vid ids
1 w 11 11
2 s 22 22
3 c 33 33
4 d 33 33联合查询结果
select * from a,b where a.ids=b.idsid name namecode ids id name vid ids
1 w 1w 11 1 w 11 11
2 s 2s 22 2 s 22 22
3 c 3c 33 3 c 33 33
4 d 4d 33 3 c 33 33
3 c 3c 33 4 d 33 33
4 d 4d 33 4 d 33 33
根据以上的表 33有4个,结果是4个很正常,你可以对a.id排重的话试试
select count(id),b_vid from
(
select a.*,b.vid b_vid from a,b where a.ids=b.ids
minus
null,null,null,null,null
)
goup by b_vid
select distinct a.id,b.vid from a,b where a.ids=b.ids) group by vid
select count(a.id),b.vid from a,b where a.ids=b.vid group by b.vid
count(a.id) ids
1 11
1 22
4 33