1,井组井关系表(表A)
列
id 井组名称 井名 (一对多关系)
1 井组1 采油井1
2 井组1 采油井2
3 井组1 注水井A
.....
2,单井注水数据表(表B)
id 井名 日期 层位 日注水量 井口注水压力 (井名+日期+层位 primary key 也就是说每口井的每个层位只能有一条注水数据) 另:每个井组只有一个注水井3,单井产量数据(表C)id 井名 日期 产液量 产油量 产水量 动液面 (井名+日期 primary key)
根据表中的数据写条组合sql语句 查出以下数据: select 日期
开井数 [(count(井号) ]
日产液量 [ sum(产液量) ]日产油量 [ sum(产油量)]综合函数率 [sum(产水量)/sum(产液量) ]平均动液面 [sum(动液面)/count(井)]from 表C where 井名 in (select 井号 from 表A where 井组名称=??)) and 日期 between ?? and ?? group by 日期 select 日期平均日注水压力 [sum(井口压力)/count(井号) ]日注水量 [ sum(日注量)]from 表B where 井名 in (select 井号 from 表A where 井组名称=??)) and 日期 between ?? and ?? group by 日期 下面是我写的俩条sql
A. select count(井号) 开井数, sum(产液量) as 日产液体量,sum(产油量) as 日产油量, round(sum(产水量)/sum(产液量),4)*100 as 综合函数率,round(sum(动液面)/count(井号),2) as 平均动液面,日期 from test_单井产量数据 where 井号 in(select 井号 from test_井组井关系表 where 井组名称='井组1'and 日期 between to_date('2008-2-1','yyyy-mm-dd') and to_date('2008-3-1','yyyy-mm-dd') group by 日期
B. select sum(日注量) as 日注水量,sum(井口压力)/count(井号) as 平均注水压力,日期 from test_单井注水数据 where 井号 in(select 井号 from test_井组井关系表 where 井组名称='井组1') and 日期 between to_date('2008-2-1','yyyy-mm-dd') and to_date('2008-3-1','yyyy-mm-dd') group by 日期
问题:1,由上面的俩条语句可否合并成一条语句 得到数据: select 日期, 开井数,平均注水压力,日注水量,日产液量,日产油量,综合函数率,平均动液面 from ......group by 日期 其中:日期为自然日期 2,可否由日数据演变为月数据
列
id 井组名称 井名 (一对多关系)
1 井组1 采油井1
2 井组1 采油井2
3 井组1 注水井A
.....
2,单井注水数据表(表B)
id 井名 日期 层位 日注水量 井口注水压力 (井名+日期+层位 primary key 也就是说每口井的每个层位只能有一条注水数据) 另:每个井组只有一个注水井3,单井产量数据(表C)id 井名 日期 产液量 产油量 产水量 动液面 (井名+日期 primary key)
根据表中的数据写条组合sql语句 查出以下数据: select 日期
开井数 [(count(井号) ]
日产液量 [ sum(产液量) ]日产油量 [ sum(产油量)]综合函数率 [sum(产水量)/sum(产液量) ]平均动液面 [sum(动液面)/count(井)]from 表C where 井名 in (select 井号 from 表A where 井组名称=??)) and 日期 between ?? and ?? group by 日期 select 日期平均日注水压力 [sum(井口压力)/count(井号) ]日注水量 [ sum(日注量)]from 表B where 井名 in (select 井号 from 表A where 井组名称=??)) and 日期 between ?? and ?? group by 日期 下面是我写的俩条sql
A. select count(井号) 开井数, sum(产液量) as 日产液体量,sum(产油量) as 日产油量, round(sum(产水量)/sum(产液量),4)*100 as 综合函数率,round(sum(动液面)/count(井号),2) as 平均动液面,日期 from test_单井产量数据 where 井号 in(select 井号 from test_井组井关系表 where 井组名称='井组1'and 日期 between to_date('2008-2-1','yyyy-mm-dd') and to_date('2008-3-1','yyyy-mm-dd') group by 日期
B. select sum(日注量) as 日注水量,sum(井口压力)/count(井号) as 平均注水压力,日期 from test_单井注水数据 where 井号 in(select 井号 from test_井组井关系表 where 井组名称='井组1') and 日期 between to_date('2008-2-1','yyyy-mm-dd') and to_date('2008-3-1','yyyy-mm-dd') group by 日期
问题:1,由上面的俩条语句可否合并成一条语句 得到数据: select 日期, 开井数,平均注水压力,日注水量,日产液量,日产油量,综合函数率,平均动液面 from ......group by 日期 其中:日期为自然日期 2,可否由日数据演变为月数据
解决方案 »
- 我在练习impdp导入数据时遇到了ORA-39083、ORA-00959错误,以下有详细日志,请大侠解释一下
- 帮忙看一下更新某个字段中部分内容的sql应该怎么写
- 这句话怎么写的
- 关于hibernate
- 两台服务器上的数据库结构一致,其中一台是主服务器,每天需要将主服务器的数据备份到辅服务器上,同时将主服务器上的数据清除
- oracle使用powerdesigner逆向生成表关系图的问题
- 急!那位耐心帮我看一看这个pl/sql调用外部dll的问题.
- 大家来说说start with和connect by的功能吧,哪些情况下会用到呢?
- 我是菜鸟 关于oracle安装的问题
- 为什么用ODBC访问ORACLE8.17会出现内存访问违例?在线等待,着急啊!
- Oracle9i中关于启动Oracle Enterprise Manager Console的问题
- 求助,存储过程嵌套返回游标问题
是date类型的 一般都是 如:2008-1-1组合下 谢谢~
select A.日期, count(井号) 开井数,avg(井口压力) 平均注水压力,sum(日注量) 日注水量,sum(产液量) 日产液量,sum(产油量) 日产油量,round(sum(产水量)/sum(产液量),4)*100 综合函数率,avg(动夜面) 平均动液面
from A,B WHERE A.日期=B.日期 group by A.日期;
select to_char(A.日期,'yyyy-mm') 月份, count(井号) 开井数,avg(井口压力) 平均注水压力,sum(日注量) 日注水量,sum(产液量) 日产液量,sum(产油量) 日产油量,round(sum(产水量)/sum(产液量),4)*100 综合函数率,avg(动夜面) 平均动液面
from A,B WHERE A.日期=B.日期
group by 月份;
from C,B WHERE B.日期=C.日期 and B.井名=C.井名 group by A.日期;
select to_char(B.日期,'yyyy-mm') 月份, count(B.井名) 开井数,avg(井口压力) 平均注水压力,sum(日注量) 日注水量,sum(产液量) 日产液量,sum(产油量) 日产油量,round(sum(产水量)/sum(产液量),4)*100 综合函数率,avg(动夜面) 平均动液面
from C,B WHERE B.日期=C.日期 and B.井名=C.井名
group by 月份;
貌似你对表结构么有理解或者我没有说清楚A表只有里存的是 井组 和 井的关系表 (一个井组中含有多口采油井 1口注水井)B表 是单井的日 注水数据 C表 是单井的日 采油数据因为这里数据基本是统计 井组的数据 所以A表 基本是计算的过滤表
哦,你原先的sql的where并在7楼的where里就可以了
B.井名=C.井名 是不成立的简单数据:示例数据:
表A:
id 井组名 井号
1 井组1 采油井1
2 井组1 采油井2
3 井组1 采油井3
4 井组1 注水井A表Bid 井号 日期 层位 日注量 井口压力
1 注水井A 2008-2-1 1 50 6
2 注水井A 2008-2-1 2 60 7
3 注水井A 2008-2-2 1 50 6
4 注水井A 2008-2-2 2 80 8
5 注水井A 2008-2-3 1 60 6
6 注水井A 2008-2-3 2 50 6表C
id 井号 日期 产液量 产油量 产水量 动液面
1 采油井1 2008-2-1 8 7 1 500
2 采油井2 2008-2-1 6 5 1 600
3 采油井3 2008-2-1 4.5 3 1.5 500
4 采油井1 2008-2-2 8 7 1 500
5 采油井2 2008-2-2 8 7 1 500
select 日期,count(井名) 开井数,sum(产液量) as 日产液体量,sum(产油量) as 日产油量, round(sum(产水量)/sum(产液量),4)*100 as 综合函数率,round(sum(动液面)/count(井号),2) as 平均动液面,null as 日注水量,null as 平均注水压力
from test_单井产量数据 where 井号 in(select 井号 from test_井组井关系表
where 井组名称='井组1'and 日期 between to_date('2008-2-1','yyyy-mm-dd') and to_date('2008-3-1','yyyy-mm-dd') group by 日期
union all
select 日期,count(井名) 开井数,null,null,null,null,sum(日注量) as 日注水量,sum(井口压力)/count(井号) as 平均注水压力
from test_单井注水数据
where 井号 in(select 井号 from test_井组井关系表 where 井组名称='井组1') and 日期 between to_date('2008-2-1','yyyy-mm-dd') and to_date('2008-3-1','yyyy-mm-dd') group by 日期
select 日期,max(开井数),max(日产液体量),max(日产油量),max(综合函数率),max(平均动液面),max(日注水量),max(平均注水压力) from
(select 日期,count(井名) 开井数,sum(产液量) as 日产液体量,sum(产油量) as 日产油量, round(sum(产水量)/sum(产液量),4)*100 as 综合函数率,round(sum(动液面)/count(井号),2) as 平均动液面,null as 日注水量,null as 平均注水压力
from test_单井产量数据 where 井号 in(select 井号 from test_井组井关系表
where 井组名称='井组1'and 日期 between to_date('2008-2-1','yyyy-mm-dd') and to_date('2008-3-1','yyyy-mm-dd') group by 日期
union all
select 日期,count(井名) 开井数,null,null,null,null,sum(日注量) as 日注水量,sum(井口压力)/count(井号) as 平均注水压力
from test_单井注水数据
where 井号 in(select 井号 from test_井组井关系表 where 井组名称='井组1') and 日期 between to_date('2008-2-1','yyyy-mm-dd') and to_date('2008-3-1','yyyy-mm-dd') group by 日期)
group by 日期;