当前位置:网站首页>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
边栏推荐
- Chapter I: essential information collection of penetration test
- Distributed e-commerce project grain mall learning notes < 3 >
- golang--channal与select
- 【系统架构】-如何评估软件架构
- Termux install openssh
- Modifying table names, deleting tables, obtaining table information, and deleting table records on specified dates for common MySQL statements
- How to default that an app is not restricted by traffic
- How to prompt
- [machine learning] case study of college entrance examination prediction based on multiple time series
- How to add a table to a drawing in ggplot2
猜你喜欢

A high-frequency interview question from a large factory: tell me about the solution of high and low interface idempotence? Solutions are attached.

Camtasia 2022 new ultra clear recording computer video

喜讯 | 祝贺Apache Linkis(incubating) 社区新增5位Committer

College Students' big factory road
![[machinetranslation] - Calculation of Bleu value](/img/c3/8f98db33eb0ab5a016621d21d971e4.png)
[machinetranslation] - Calculation of Bleu value

Here comes the official zero foundation introduction jetpack compose Chinese course!

程序员的八年工资变动,令网友羡慕不已:你一个月顶我一年工资

财富自由技能:把自己产品化

Classic quotations from "human nature you must not know"

Win10 computer power management turns on excellence mode
随机推荐
R语言 生存分析
Dreamcamera2 video recording, playing without sound, recording function is normal, using a third-party application for video recording, playing with sound
Camtasia 2022 new ultra clear recording computer video
学习太极创客 — MQTT(五)发布、订阅和取消订阅
OpenAPI 3.0 specification - Food Guide
我在中山,到哪里开户比较好?网上开户是否安全么?
Golang--channel and select
R 语言降维的 PCA 与自动编码器
网上开户选哪个证券公司?网上开户是否安全么?
How to default that an app is not restricted by traffic
财富自由技能:把自己产品化
Classic quotations from "human nature you must not know"
High availability in Internet three highs (high concurrency, high performance and high availability)
应届毕业生谈毕业的故事
Camtasia 2022全新版超清錄制電腦視頻
Possible values for @supply in kotlin
[solution] cmake was unable to find a build program corresponding to "UNIX makefiles"
Arthas(阿尔萨斯) 能为你做什么?
【解决】联想拯救者vmware启动虚拟机蓝屏重启问题
业务流程图设计