oracle如何分組統計,oracle分組統計,再求和

oracle分組統計(group)

select pkdz.id ,zsmx.id as zsmxid,pzty.typh_q, pzty.typh_z, pzty.szsk, skxx.swjgid,zsmx.je from pz_pztyjl pzty

創新互聯從2013年創立,是專業互聯網技術服務公司,擁有項目做網站、成都網站設計網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元臨高做網站,已為上家服務,為臨高各地企業和個人服務,聯系電話:13518219792

join pz_pkdzjl pkdz on (pzty.pkdzjl_id = pkdz.id )

join sk_hd_zsmx zsmx on ( pkdz.id = zsmx.tyjks_id )

join sk_zt_skxx skxx on (zsmx.skxx_id = skxx.id)

order by pkdz.id asc, zsmx.id asc

Oracle數據庫按時間進行分組統計數據的方法

Oracle按不同時間分組統計的sql

如下表table1:

日期(exportDate)

數量(amount)

--------------

-----------

14-2月

-08

20

10-3月

-08

2

14-4月

-08

6

14-6月

-08

75

24-10月-09

23

14-11月-09

45

04-8月

-10

5

04-9月

-10

44

04-10月-10

88

注意:為了顯示更直觀,如下查詢已皆按相應分組排序

1.按年份分組

select

to_char(exportDate,'yyyy'),sum(amount)

from

table1

group

by

to_char(exportDate,'yyyy');

年份

數量

-----------------------------

2009

68

2010

137

2008

103

2.按月份分組

select

to_char(exportDate,'yyyy-mm'),sum(amount)

from

table1

group

by

to_char(exportDate,'yyyy-mm')

order

by

to_char(exportDate,'yyyy-mm');

月份

數量

-----------------------------

2008-02

20

2008-03

2

2008-04

6

2008-06

75

2009-10

23

2009-11

45

2010-08

5

2010-09

44

2010-10

88

3.按季度分組

select

to_char(exportDate,'yyyy-Q'),sum(amount)

from

table1

group

by

to_char(exportDate,'yyyy-Q')

order

by

to_char(exportDate,'yyyy-Q');

季度

數量

------------------------------

2008-1

22

2008-2

81

2009-4

68

2010-3

49

2010-4

88

4.按周分組

select

to_char(exportDate,'yyyy-IW'),sum(amount)

from

table1

group

by

to_char(exportDate,'yyyy-IW')

order

by

to_char(exportDate,'yyyy-IW');

數量

------------------------------

2008-07

20

2008-11

2

2008-16

6

2008-24

75

2009-43

23

2009-46

45

2010-31

5

2010-35

44

2010-40

88

PS:Oracle按時間段分組統計

想要按時間段分組查詢,首先要了解level,connect

by,oracle時間的加減.

關于level這里不多說,我只寫出一個查詢語句:

----level

是一個偽例

select

level

from

dual

connect

by

level

=10

---結果:

1

2

3

4

5

6

7

8

9

10

oracle時間的加減看看試一下以下sql語句就會知道:

select

sysdate

-1

from

dual

----結果減一天,也就24小時

select

sysdate-(1/2)

from

dual

-----結果減去半天,也就12小時

select

sysdate-(1/24)

from

dual

-----結果減去1

小時

select

sysdate-((1/24)/12)

from

dual

----結果減去5分鐘

select

sydate-(level-1)

from

dual

connect

by

level=10

---結果是10間隔1天的時間

下面是本次例子:

select

dt,

count(satisfy_degree)

as

num

from

T_DEMO

i

,

(select

sysdate

-

(level-1)

*

2

dt

from

dual

connect

by

level

=

10)

d

where

i.satisfy_degree='satisfy_1'

and

i.insert_timedt

and

i.insert_time

d.dt-2

group

by

d.dt

例子中的sysdate

-

(level-1)

*

2得到的是一個間隔是2天的時間

group

by

d.dt

也就是兩天的時間間隔分組查詢

自己實現例子:

create

table

A_HY_LOCATE1

(

MOBILE_NO

VARCHAR2(32),

LOCATE_TYPE

NUMBER(4),

AREA_NO

VARCHAR2(32),

CREATED_TIME

DATE,

AREA_NAME

VARCHAR2(512),

);

select

(sysdate-13)-(level-1)/4

from

dual

connect

by

level=34

--從第一條時間記錄開始(sysdate-13)為表中的最早的日期,“34”出現的分組數(一天按每六個小時分組

就應該為4)

一下是按照每6個小時分組

select

mobile_no,area_name,max(created_time

),dt,

count(*)

as

num

from

a_hy_locate1

i

,

(select

(sysdate-13)-(level-1)/4

dt

from

dual

connect

by

level

=

34)

d

where

i.locate_type

=

1

and

i.created_timedt

and

i.created_time

d.dt-1/4

group

by

mobile_no,area_name,d.dt

另外一個方法:

--按六小時分組

select

trunc(to_number(to_char(created_time,

'hh24'))

/

6),count(*)

from

t_test

where

created_time

trunc(sysdate

-

40)

group

by

trunc(to_number(to_char(created_time,

'hh24'))

/

6)

--按12小時分組

select

trunc(to_number(to_char(created_time,

'hh24'))

/

6),count(*)

from

t_test

where

created_time

trunc(sysdate

-

40)

group

by

trunc(to_number(to_char(created_time,

'hh24'))

/

6)

Oracle如何對一個多值字段進行分組統計

info表的use字段會有重復的嗎比如userA@userA,這樣算一個還是2個?

如果沒有重復或只算一個的話可以這么統計,不過效率是慢點....

select

userID,(select

count(1)

from

info

where

userID

like

'%'

||

trim(a.userID)

||

'%')

from

user

a;

關于oracle怎么做多次分組

以NO字段為主,進行分組。

select a.no,sum(a.金額) from table a group by a.no

同一個NO,會對應不同的姓名。

select a.no,a.姓名,sum(a.金額) from table a group by a.no,a.姓名

看不懂

目標語句:當收費醒目包含‘鹽’這一項,則統計no='10' 且 姓名=‘張三’,所有收費項目對...

select a.項目,sum(a.金額) from table a where a.收費項目= '1' and a.no = '10' and a.姓名=‘張三’ group by a.項目

網站名稱:oracle如何分組統計,oracle分組統計,再求和
文章源于:http://m.kartarina.com/article26/hegpcg.html

成都網站建設公司_創新互聯,為您提供網站設計、靜態網站營銷型網站建設、企業網站制作、動態網站、網站維護

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

網站托管運營
主站蜘蛛池模板: 国产免费久久久久久无码| 成在线人免费无码高潮喷水| 东京热av人妻无码专区| 国产V亚洲V天堂无码| 无码丰满熟妇浪潮一区二区AV| 成人免费无遮挡无码黄漫视频| 中文字幕久无码免费久久| 精品无码久久久久久尤物| 亚洲AV无码成H人在线观看| 国产精品无码久久久久久| 久久AV高清无码| 人妻无码精品久久亚瑟影视| 亚洲av无码专区在线电影| 日韩毛片无码永久免费看| 色综合AV综合无码综合网站| 精品无码黑人又粗又大又长| 久久久久久国产精品无码超碰 | 亚洲av永久无码| 国精无码欧精品亚洲一区| 国产精品成人99一区无码| 免费无码中文字幕A级毛片| 亚洲中文字幕无码专区| 无码无套少妇毛多18PXXXX| 亚洲AV无码码潮喷在线观看| 国产精品无码久久久久| 免费无码又爽又刺激毛片| 亚洲中文字幕无码中文| 久久亚洲精品无码aⅴ大香| 国产在线无码一区二区三区视频| 亚洲AV无码成H人在线观看 | 无码A级毛片日韩精品| 91精品日韩人妻无码久久不卡 | 伊人久久精品无码av一区| 无码av高潮喷水无码专区线| 无码精品久久久久久人妻中字| 国产午夜无码精品免费看| 国产AV无码专区亚洲AVJULIA| 熟妇人妻系列av无码一区二区| 亚洲av无码成人精品区在线播放 | 成人无码A区在线观看视频| 久久无码AV中文出轨人妻|