当前位置:网站首页>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
边栏推荐
- Fresh graduates talk about their graduation stories
- Share some remote office experience in Intranet operation | community essay solicitation
- High availability in Internet three highs (high concurrency, high performance and high availability)
- 2022年挖财商学院证券开户安全嘛?
- 浅谈虚拟内存与项目开发中的OOM问题
- 请指教同花顺软件究竟是什么?在线开户安全么?
- What is the sudden power failure of iPhone and how to solve it?
- The "more" option of Spreadtrum platform dearmcamera2 is removed
- Learn Tai Chi Maker - mqtt (IV) server connection operation
- 在 R 中创建非线性最小二乘检验
猜你喜欢
![[solution] the blue screen restart problem of the virtual machine started by the VMware of Lenovo Savior](/img/c3/892ce2f45abea7140df98cabc1431b.png)
[solution] the blue screen restart problem of the virtual machine started by the VMware of Lenovo Savior
![[machinetranslation] - Calculation of Bleu value](/img/c3/8f98db33eb0ab5a016621d21d971e4.png)
[machinetranslation] - Calculation of Bleu value

业务流程图设计

Explain the JVM clearly at one time and don't be asked by the interviewer again

第一章:渗透测试的本质信息收集

How do I take a screenshot of the iPad? 7 ways to take quick screenshots of iPad

Camtasia 2022 new ultra clear recording computer video

The programmer's eight-year salary change has made netizens envious: you pay me one year's salary per month

Camtasia 2022 nouvelle vidéo d'ordinateur d'enregistrement ultra - clair

数据库的授权
随机推荐
NoSQL之Redis配置与优化
无法上网问题解决过程
What happens when the cloud answer does not display the third-party login button
请指教同花顺开户选选择哪家券商比较好?网上开户是否安全么?
多测师拱墅校区肖sir_jenkins中搭建出现页面报错
How to prompt
golang--channal与select
The programmer's eight-year salary change has made netizens envious: you pay me one year's salary per month
Little p weekly Vol.10
OpenAPI 3.0 规范-食用指南
Audio video and CPU architecture
Technology is to be studied
7 tips to change your life
Share some remote office experience in Intranet operation | community essay solicitation
学习太极创客 — MQTT(五)发布、订阅和取消订阅
Introduction to bloc: detailed explanation of cube
2021-08-04
应届毕业生谈毕业的故事
The difference between like,%, - in database query SQL
Redis configuration and optimization of NoSQL