当前位置:网站首页>Oracle exercise
Oracle exercise
2022-06-26 02:56:00 【qq_ forty-five million eight hundred and forty-nine thousand tw】
ORACLE Chapter II answers to after class exercises
by 《 Tap water charging system 》 Develop functions related to the statistics module
1. Daily charge sheet ( total )
Count the charges for a day , Summarize by region , The effect is as follows :
sentence :
select (select name from T_AREA where id= areaid ) Area ,
sum(usenum)/1000 “ water consumption ( Tons of )” ,sum(money) amount of money
from T_ACCOUNT
where to_char(feedate,‘yyyy-mm-dd’)=‘2012-05-14’
group by areaid
2. Daily charge sheet ( Toll collector )
Count the charges of a toll collector on a certain day , Summarize by region , The effect is as follows :
sentence :
select (select name from T_AREA where id= areaid ) Area ,
sum(usenum)/1000 “ water consumption ( Tons of )” ,sum(money) amount of money
from T_ACCOUNT
where to_char(feedate,‘yyyy-mm-dd’)=‘2012-05-14’
and feeuser=2
group by areaid
3. Monthly charge Report ( total )
Count the charging records of a certain month in a certain year , Summarize by region
sentence :
select (select name from T_AREA where id= areaid ) Area ,
sum(usenum)/1000 “ water consumption ( Tons of )” ,sum(money) amount of money
from T_ACCOUNT
where to_char(feedate,‘yyyy-mm’)=‘2012-05’
group by areaid
4. Monthly charge Report ( Toll collector )
Count the charging records of a toll collector in a year and a month , Summarize by region
sentence :
select (select name from T_AREA where id= areaid ) Area ,
sum(usenum)/1000 “ water consumption ( Tons of )” ,sum(money) amount of money
from T_ACCOUNT
where to_char(feedate,‘yyyy-mm’)=‘2012-05’ and feeuser=2
group by areaid
5. Annual statement of charges ( Sub regional statistics )
Statistics of charges in a certain year , Summarize by region , The effect is as follows :
sentence :
select (select name from T_AREA where id= areaid ) Area ,
sum(usenum)/1000 “ water consumption ( Tons of )” ,sum(money) amount of money
from T_ACCOUNT
where to_char(feedate,‘yyyy’)=‘2012’
group by areaid
6. Annual statement of charges ( Statistics by month )
Statistics of charges in a certain year , Summarize by month , The effect is as follows
sentence :
select to_char(feedate,‘mm’) month ,sum(usenum)/1000 Using tons ,sum(money) amount of money
from T_ACCOUNT
where to_char(feedate,‘yyyy’)=‘2013’
GROUP BY to_char(feedate,‘mm’)
ORDER BY to_char(feedate,‘mm’)
7. Annual statement of charges ( Statistics by month )
Statistics of charges in a certain year , Summarize by month , The effect is as follows
sentence :
select ‘ water consumption ( Tons of )’ Statistical items ,
sum (case when to_char(feedate,‘mm’)=‘01’ then usenum else 0 end )/1000 January ,
sum (case when to_char(feedate,‘mm’)=‘02’ then usenum else 0 end )/1000 February ,
sum (case when to_char(feedate,‘mm’)=‘03’ then usenum else 0 end )/1000 March ,
sum (case when to_char(feedate,‘mm’)=‘04’ then usenum else 0 end )/1000 April ,
sum (case when to_char(feedate,‘mm’)=‘05’ then usenum else 0 end )/1000 May ,
sum (case when to_char(feedate,‘mm’)=‘06’ then usenum else 0 end )/1000 June ,
sum (case when to_char(feedate,‘mm’)=‘07’ then usenum else 0 end )/1000 July ,
sum (case when to_char(feedate,‘mm’)=‘08’ then usenum else 0 end )/1000 August ,
sum (case when to_char(feedate,‘mm’)=‘09’ then usenum else 0 end )/1000 September ,
sum (case when to_char(feedate,‘mm’)=‘10’ then usenum else 0 end )/1000 October ,
sum (case when to_char(feedate,‘mm’)=‘11’ then usenum else 0 end )/1000 November ,
sum (case when to_char(feedate,‘mm’)=‘12’ then usenum else 0 end )/1000 December
from T_ACCOUNT
where to_char(feedate,‘yyyy’)=‘2013’
UNION ALL
select ‘ amount of money ( element )’ Statistical items ,
sum (case when to_char(feedate,‘mm’)=‘01’ then money else 0 end ) January ,
sum (case when to_char(feedate,‘mm’)=‘02’ then money else 0 end ) February ,
sum (case when to_char(feedate,‘mm’)=‘03’ then money else 0 end ) March ,
sum (case when to_char(feedate,‘mm’)=‘04’ then money else 0 end ) April ,
sum (case when to_char(feedate,‘mm’)=‘05’ then money else 0 end ) May ,
sum (case when to_char(feedate,‘mm’)=‘06’ then money else 0 end ) June ,
sum (case when to_char(feedate,‘mm’)=‘07’ then money else 0 end ) July ,
sum (case when to_char(feedate,‘mm’)=‘08’ then money else 0 end ) August ,
sum (case when to_char(feedate,‘mm’)=‘09’ then money else 0 end ) September ,
sum (case when to_char(feedate,‘mm’)=‘10’ then money else 0 end ) October ,
sum (case when to_char(feedate,‘mm’)=‘11’ then money else 0 end ) November ,
sum (case when to_char(feedate,‘mm’)=‘12’ then money else 0 end ) December
from T_ACCOUNT
where to_char(feedate,‘yyyy’)=‘2013’
8. Statistical water consumption , Amount of charge ( Statistics by type )
The water consumption of each type of residents shall be counted according to the type of owner ( Integers , rounding ) And the amount charged , If this type has no data in the account table, the value must also be listed as 0 The record of , The effect is as follows :
sentence :
select ow.name,
nvl( round(sum(usenum)/1000),0) “ water consumption ( Tons of )” , nvl( sum(money),0) amount of money
from T_OWNERTYPE ow ,T_ACCOUNT ac
where ow.id=ac.ownertype(+)
group by ow.name
analysis : The knowledge points used here include the left outer connection 、sum()、 grouping group by 、round() and nvl()
9. Count the number of owners in each area , And list the total
sentence :
select ar.name Area ,count(ow.id) Number of owners
from T_AREA ar ,T_OWNERS ow,T_ADDRESS ad
where ad.id=ow.addressid and ad.areaid=ar.id
group by ar.name
union all
select ‘ total ’,count(1) from T_OWNERS
10. Count the number of owners in each area , If there is no owner in the area, the number of households should also be listed 0
Pictured :
sentence :
select ar.name Area ,count(owad.id) Number of owners
from T_AREA ar ,
(
select ow.id,ow.name,ad.areaid from T_OWNERS ow,T_ADDRESS ad where ow.addressid=ad.id
)
owad
where ar.id=owad.areaid(+)
group by ar.name
边栏推荐
- [defect detection] automatic defect detection of printed circuit board based on Matlab GUI [including Matlab source code 1912]
- 【机器学习】基于多元时间序列对高考预测分析案例
- OpenAPI 3.0 规范-食用指南
- PCA and automatic encoder for dimension reduction of R language
- Thirty ninth step
- Termux install openssh
- Install development cross process communication
- Learn Tai Chi Maker - mqtt (IV) server connection operation
- Little p weekly Vol.10
- 小 P 周刊 Vol.10
猜你喜欢

分享一些在内网操作的远程办公经验| 社区征文

High availability in Internet three highs (high concurrency, high performance and high availability)

How to add a regression equation to a plot in R

应届毕业生谈毕业的故事

Possible values for @supply in kotlin

附加:HikariCP连接池简述;(并没有深究,只是对HikariCP连接池有个基本认识)

浅谈虚拟内存与项目开发中的OOM问题

OpenAPI 3.0 规范-食用指南

How to solve the problem that the iPhone 13 lock screen cannot receive the wechat notification prompt?

第一章:渗透测试的本质信息收集
随机推荐
Cox 回归模型
Dual batteries in series, hardware design
Share some remote office experience in Intranet operation | community essay solicitation
第一章:渗透测试的本质信息收集
Translation notes of orb-slam series papers
UE5全局光照系统Lumen解析与优化
MySQL updates records based on the queried data
Gold three silver four~
vulhub复现一 activemq
Dreamcamera2 record key prompt sound into video during video recording
无法上网问题解决过程
我在中山,到哪里开户比较好?网上开户是否安全么?
Redis Lua沙盒绕过命令执行(CVE-2022-0543)
UTONMOS坚持“藏品、版权”双优原则助力传统文化高质量发展
使用 AnnotationDbi 转换 R 中的基因名称
Modifying table names, deleting tables, obtaining table information, and deleting table records on specified dates for common MySQL statements
R 语言降维的 PCA 与自动编码器
OpenAPI 3.0 规范-食用指南
Gd32 ADC acquisition voltage
IPhone 13 screen stuck black, unable to shut down? How to solve