已知有A表
ID, Name 两字段,.关系表R
ID, A_ID, B_ID其中A_ID对应的是A表中的ID.求一VIEW的字段为
A_ID, A_NAME CountA_ID为A表中的ID,A_NAME 为A表中的Name, Count 为A_ID=某值时,在R表中的记录数.example:
Table A
ID Name
1 A1
2 A2
3 A3
4 A4Table R
ID A_ID B_ID
1 1 1
2 1 2
3 1 3
4 2 2
5 2 5
6 3 3
7 3 4View
A_ID A_NAME Count
1 A1 3
2 A2 2
3 A3 2
ID, Name 两字段,.关系表R
ID, A_ID, B_ID其中A_ID对应的是A表中的ID.求一VIEW的字段为
A_ID, A_NAME CountA_ID为A表中的ID,A_NAME 为A表中的Name, Count 为A_ID=某值时,在R表中的记录数.example:
Table A
ID Name
1 A1
2 A2
3 A3
4 A4Table R
ID A_ID B_ID
1 1 1
2 1 2
3 1 3
4 2 2
5 2 5
6 3 3
7 3 4View
A_ID A_NAME Count
1 A1 3
2 A2 2
3 A3 2
解决方案 »
- RH 3.2.2-5版本能装oracle10g么
- data guard如何在主库宕掉的情况下,将逻辑备库转换成主库?
- ora-27101 数据库实例启动不了
- 关于建立db link的时候密码为空如何解决?
- 紧急!! imp 的导入问题?
- 求一个方法:在插入一条记录,流水号字段自动增长1,但不能用序列。
- PRO*C程序连接池问题
- 如何选择使用数据库(sql server 和 Oralce ),它们之间的差别是什么,请各位数据库大虾参与讨论,公司要我出个方案,急啊!
- 关于Oracle Listener的问题
- 如何在pl/sql Develper中写存储过程
- oarcle重建索引时锁表报的错误号
- 如何学习ORACLE?
SQL> select d.deptno,d.dname, t.empcount from dept d,
2 (select deptno, count(*) empcount from emp group by deptno) t
3 where d.deptno=t.deptno; DEPTNO DNAME EMPCOUNT
---------- -------------- ----------
10 ACCOUNTING 3
20 RESEARCH 5
30 SALES 6
select A_id,name,count(R.id) from A,R where A.id = R.A_id group by A_id,name
)
楼上都是正解,你要的是视图,楼上就可以select * from 视图 就OK了
--直接来create view v_count
as
select a.id,a.name,count(*) 数量
from a,r
where a.id=r.a_id
group by a.id,a.name