Oracle水廠收費系統練習拓展

2021-08-17 18:39:50 字數 4807 閱讀 6083

title: oracle水廠收費系統練習拓展

date: 2018-1-28 22:05:23

categories: oracle

tags: oracle

-- 統計某日的收費,按區域分組彙總

select (select name from t_area where id = t.areaid) 區域, sum(usernum)/1000 用水量, sum(money) 金額

from t_account t

where to_char(t.feedate, 'yyyy-mm-dd')='2012-05-14'

group

by t.areaid;

-- 注意:以上語句中areaid,如果在沒有分組的情況下,不能直接跟sum函式拼接查詢

-- 統計某收費員某日的收費,按區域分組彙總

select (select name from t_area where id = ac.areaid) 區域, sum(usernum)/1000 用水量, sum(money) 金額

from t_account ac

where to_char(ac.feedate, 'yyyy-mm-dd') = '2012-05-14'

and ac.feeuserid = 2

group

by ac.areaid;

-- 統計某年某月的收費記錄,按區域分組彙總

select (select name from t_area where id = ac.areaid) 區域, sum(usernum)/1000 用水量, sum(money) 金額

from t_account ac

where to_char(ac.feedate, 'yyyy-mm') = '2012-05'

group

by ac.areaid;

select (select name from t_area where id = ac.areaid) 區域, sum(usernum)/1000 用水量, sum(money) 金額

from t_account ac

where to_char(ac.meterdate, 'yyyy-mm-dd') = '2018-01-26'

group

by ac.areaid;

select to_char(ac.meterdate, 'yyyy-mm-dd') from t_account ac

-- 統計某收費員某年某月的收費記錄,按區域分組彙總

select (select name from t_area where id = ac.areaid) 區域, sum(usernum)/1000 用水量, sum(money) 金額

from t_account ac

where to_char(ac.feedate, 'yyyy-mm') = '2012-05'

and ac.feeuserid = 2

group

by ac.areaid;

-- 統計某年收費情況,按區域分組彙總

select (select name from t_area where id = ac.areaid) 區域, sum(usernum)/1000 用水量, sum(money) 金額

from t_account ac

where to_char(ac.feedate, 'yyyy') = '2012'

group

by ac.areaid;

-- 統計某年收費情況,按月份分組彙總

select ac.month 月份, sum(usernum)/1000 用水量, sum(money) 金額

from t_account ac

where to_char(ac.feedate, 'yyyy') = '2013'

group

by ac.month

order

by ac.month;

-- 統計某年收費情況,按月份分組彙總

select

'用水量'統計項,

sum(case

when ac.month = '01'

then usernum end) 一月,

sum(case

when ac.month = '02'

then usernum end) 二月,

sum(case

when ac.month = '03'

then usernum end) 三月,

sum(case

when ac.month = '04'

then usernum end) 四月,

sum(case

when ac.month = '05'

then usernum end) 五月,

sum(case

when ac.month = '06'

then usernum end) 六月,

sum(case

when ac.month = '07'

then usernum end) 七月,

sum(case

when ac.month = '08'

then usernum end) 八月,

sum(case

when ac.month = '09'

then usernum end) 九月,

sum(case

when ac.month = '10'

then usernum end) 十月,

sum(case

when ac.month = '11'

then usernum end) 十一月,

sum(case

when ac.month = '12'

then usernum end) 十二月

from t_account ac where to_char(ac.feedate, 'yyyy') = '2013'

union

allselect

'金額'統計項,

sum(case

when ac.month = '01'

then money end) 一月,

sum(case

when ac.month = '02'

then money end) 二月,

sum(case

when ac.month = '03'

then money end) 三月,

sum(case

when ac.month = '04'

then money end) 四月,

sum(case

when ac.month = '05'

then money end) 五月,

sum(case

when ac.month = '06'

then money end) 六月,

sum(case

when ac.month = '07'

then money end) 七月,

sum(case

when ac.month = '08'

then money end) 八月,

sum(case

when ac.month = '09'

then money end) 九月,

sum(case

when ac.month = '10'

then money end) 十月,

sum(case

when ac.month = '11'

then money end) 十一月,

sum(case

when ac.month = '12'

then money end) 十二月

from t_account ac where to_char(ac.feedate, 'yyyy') = '2013';

-- 根據業主型別分別統計每種居民的用水量(整數,四捨五入)及收費金額 ,如果該型別在臺賬表中無資料也需要列出值為0的記錄

select ow.name, nvl(round(sum(usernum)/1000), 0) 用水量, nvl(sum(money),0) 金額

from t_ownertype ow, t_account ac

where ow.id=ac.ownertypeid(+)

group

by ow.name;

-- 統計每個區域的業主戶數,並列出合計

select ar.name 區域, count(ow.id) 業主戶數

from t_area ar, t_owners ow, t_address ad

where ar.id=ad.areaid and ow.addressid=ad.id

group

by ar.name

union

allselect

'統計', count(*) from t_owners;

-- 統計每個區域的業主戶數,如果該區域沒有業主戶數也要列出0

select ar.name 區域,count(owad.id) 業主戶數

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

python 作業系統(練習)

京東二面筆試題 1 生成乙個大檔案ips.txt,要求1200行,每行隨機為172.25.254.0 24段的ip 2.讀取ips.txt檔案統計這個檔案中ip出現頻率排前10的ip import random def create ip file filename ip 172.25.254.st...

使用者管理系統練習 python

userinfor defregister global userinfor name input 請輸入使用者名稱 if name in userinfor 判斷是否被註冊過 print 該使用者名稱已被註冊 else passwd input 請輸入密碼 userinfor name passw...

C 簡單登入註冊系統練習

using system using system.collections.generic using system.linq using system.text using system.threading.tasks using system.io 控制檔案流 using system.text...