oracle中如何求分位 oracle 四分位數(shù)

如何在oracle中求95分位數(shù)

對(duì)大多數(shù)應(yīng)用來(lái)說(shuō),應(yīng)該慎重地考慮是否需要使用集群范圍的緩存,因?yàn)樵L問(wèn)的速度不一定會(huì)比直接訪問(wèn)數(shù)據(jù)庫(kù)數(shù)據(jù)的速度快多少。

成都創(chuàng)新互聯(lián)主要從事成都網(wǎng)站制作、做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)淮濱,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢建站服務(wù):18982081108

oracle sql 如何選取數(shù)據(jù)集中四分位數(shù)(min,25%,MED,75%max)

-- 首先,以超級(jí)管理員的身份登錄oracle

sqlplus sys/bjsxt as sysdba

--然后,解除對(duì)scott用戶的鎖

alter user scott account unlock;

--那么這個(gè)用戶名就能使用了。

--(默認(rèn)全局?jǐn)?shù)據(jù)庫(kù)名orcl)

1、select ename, sal * 12 from emp; --計(jì)算年薪

2、select 2*3 from dual; --計(jì)算一個(gè)比較純的數(shù)據(jù)用dual表

3、select sysdate from dual; --查看當(dāng)前的系統(tǒng)時(shí)間

4、select ename, sal*12 anuual_sal from emp; --給搜索字段更改名稱(chēng)(雙引號(hào) keepFormat 別名有特殊字符,要加雙引號(hào))。

5、--任何含有空值的數(shù)學(xué)表達(dá)式,最后的計(jì)算結(jié)果都是空值。

6、select ename||sal from emp; --(將sal的查詢結(jié)果轉(zhuǎn)化為字符串,與ename連接到一起,相當(dāng)于Java中的字符串連接)

7、select ename||'afasjkj' from emp; --字符串的連接

8、select distinct deptno from emp; --消除deptno字段重復(fù)的值

9、select distinct deptno , job from emp; --將與這兩個(gè)字段都重復(fù)的值去掉

10、select * from emp where deptno=10; --(條件過(guò)濾查詢)

11、select * from emp where empno 10; --大于 過(guò)濾判斷

12、select * from emp where empno 10 --不等于 過(guò)濾判斷

13、select * from emp where ename 'cba'; --字符串比較,實(shí)際上比較的是每個(gè)字符的AscII值,與在Java中字符串的比較是一樣的

14、select ename, sal from emp where sal between 800 and 1500; --(between and過(guò)濾,包含800 1500)

15、select ename, sal, comm from emp where comm is null; --(選擇comm字段為null的數(shù)據(jù))

16、select ename, sal, comm from emp where comm is not null; --(選擇comm字段不為null的數(shù)據(jù))

17、select ename, sal, comm from emp where sal in (800, 1500,2000); --(in 表范圍)

18、select ename, sal, hiredate from emp where hiredate '02-2月-1981'; --(只能按照規(guī)定的格式寫(xiě))

19、select ename, sal from emp where deptno =10 or sal 1000;

20、select ename, sal from emp where deptno =10 and sal 1000;

21、select ename, sal, comm from emp where sal not in (800, 1500,2000); --(可以對(duì)in指定的條件進(jìn)行取反)

22、select ename from emp where ename like '%ALL%'; --(模糊查詢)

23、select ename from emp where ename like '_A%'; --(取第二個(gè)字母是A的所有字段)

24、select ename from emp where ename like '%/%%'; --(用轉(zhuǎn)義字符/查詢字段中本身就帶%字段的)

25、select ename from emp where ename like '%$%%' escape '$'; --(用轉(zhuǎn)義字符/查詢字段中本身就帶%字段的)

26、select * from dept order by deptno desc; (使用order by desc字段 對(duì)數(shù)據(jù)進(jìn)行降序排列 默認(rèn)為升序asc);

27、select * from dept where deptno 10 order by deptno asc; --(我們可以將過(guò)濾以后的數(shù)據(jù)再進(jìn)行排序)

28、select ename, sal, deptno from emp order by deptno asc, ename desc; --(按照多個(gè)字段排序 首先按照deptno升序排列,當(dāng)detpno相同時(shí),內(nèi)部再按照ename的降序排列)

29、select lower(ename) from emp; --(函數(shù)lower() 將ename搜索出來(lái)后全部轉(zhuǎn)化為小寫(xiě));

30、select ename from emp where lower(ename) like '_a%'; --(首先將所搜索字段轉(zhuǎn)化為小寫(xiě),然后判斷第二個(gè)字母是不是a)

31、select substr(ename, 2, 3) from emp; --(使用函數(shù)substr() 將搜素出來(lái)的ename字段從第二個(gè)字母開(kāi)始截,一共截3個(gè)字符)

32、select chr(65) from dual; --(函數(shù)chr() 將數(shù)字轉(zhuǎn)化為AscII中相對(duì)應(yīng)的字符)

33、select ascii('A') from dual; --(函數(shù)ascii()與32中的chr()函數(shù)是相反的 將相應(yīng)的字符轉(zhuǎn)化為相應(yīng)的Ascii編碼) )

34、select round(23.232) from dual; --(函數(shù)round() 進(jìn)行四舍五入操作)

35、select round(23.232, 2) from dual; --(四舍五入后保留的小數(shù)位數(shù) 0 個(gè)位 -1 十位)

36、select to_char(sal, '$99,999.9999')from emp; --(加$符號(hào)加入千位分隔符,保留四位小數(shù),沒(méi)有的補(bǔ)零)

37、select to_char(sal, 'L99,999.9999')from emp; --(L 將貨幣轉(zhuǎn)化為本地幣種此處將顯示¥人民幣)

38、select to_char(sal, 'L00,000.0000')from emp; --(補(bǔ)零位數(shù)不一樣,可到數(shù)據(jù)庫(kù)執(zhí)行查看)

39、select to_char(hiredate, 'yyyy-MM-DD HH:MI:SS') from emp; --(改變?nèi)掌谀J(rèn)的顯示格式)

40、select to_char(sysdate, 'yyyy-MM-DD HH:MI:SS') from dual; --(用12小時(shí)制顯示當(dāng)前的系統(tǒng)時(shí)間)

41、select to_char(sysdate, 'yyyy-MM-DD HH24:MI:SS') from dual; --(用24小時(shí)制顯示當(dāng)前的系統(tǒng)時(shí)間)

42、select ename, hiredate from emp where hiredate to_date('1981-2-20 12:24:45','YYYY-MM-DD HH24:MI:SS'); --(函數(shù)to-date 查詢公司在所給時(shí)間以后入職的人員)

43、select sal from emp where sal to_number('$1,250.00', '$9,999.99'); --(函數(shù)to_number()求出這種薪水里帶有特殊符號(hào)的)

44、select ename, sal*12 + nvl(comm,0) from emp; --(函數(shù)nvl() 求出員工的"年薪 + 提成(或獎(jiǎng)金)問(wèn)題")

45、select max(sal) from emp; -- (函數(shù)max() 求出emp表中sal字段的最大值)

46、select min(sal) from emp; -- (函數(shù)max() 求出emp表中sal字段的最小值)

47、select avg(sal) from emp; --(avg()求平均薪水);

48、select to_char(avg(sal), '999999.99') from emp; --(將求出來(lái)的平均薪水只保留2位小數(shù))

49、select round(avg(sal), 2) from emp; --(將平均薪水四舍五入到小數(shù)點(diǎn)后2位)

50、select sum(sal) from emp; --(求出每個(gè)月要支付的總薪水)

------------------------/組函數(shù)(共5個(gè)):將多個(gè)條件組合到一起最后只產(chǎn)生一個(gè)數(shù)據(jù)------min() max() avg() sum() count()----------------------------/

51、select count(*) from emp; --求出表中一共有多少條記錄

52、select count(*) from emp where deptno=10; --再要求一共有多少條記錄的時(shí)候,還可以在后面跟上限定條件

53、select count(distinct deptno) from emp; --統(tǒng)計(jì)部門(mén)編號(hào)前提是去掉重復(fù)的值

------------------------聚組函數(shù)group by() --------------------------------------

54、select deptno, avg(sal) from emp group by deptno; --按照deptno分組,查看每個(gè)部門(mén)的平均工資

55、select max(sal) from emp group by deptno, job; --分組的時(shí)候,還可以按照多個(gè)字段進(jìn)行分組,兩個(gè)字段不相同的為一組

56、select ename from emp where sal = (select max(sal) from emp); --求出

57、select deptno, max(sal) from emp group by deptno; --搜素這個(gè)部門(mén)中薪水最高的的值

--------------------------------------------------having函數(shù)對(duì)于group by函數(shù)的過(guò)濾 不能用where--------------------------------------

58、select deptno, avg(sal) from emp group by deptno having avg(sal) 2000; (order by )--求出每個(gè)部門(mén)的平均值,并且要 2000

59、select avg(sal) from emp where sal 1200 group by deptno having avg(sal) 1500 order by avg(sal) desc;--求出sal1200的平均值按照deptno分組,平均值要1500最后按照sal的倒序排列

60、select ename,sal from emp where sal (select avg(sal) from emp); --求那些人的薪水是在平均薪水之上的。

61、select ename, sal from emp join (select max(sal) max_sal ,deptno from emp group by deptno) t on (emp.sal = t.max_sal and emp.deptno=t.deptno); --查詢每個(gè)部門(mén)中工資最高的那個(gè)人

------------------------------/等值連接--------------------------------------

62、select e1.ename, e2.ename from emp e1, emp e2 where e1.mgr = e2.empno; --自連接,把一張表當(dāng)成兩張表來(lái)用

63、select ename, dname from emp, dept; --92年語(yǔ)法 兩張表的連接 笛卡爾積。

64、select ename, dname from emp cross join dept; --99年語(yǔ)法 兩張表的連接用cross join

65、select ename, dname from emp, dept where emp.deptno = dept.deptno; -- 92年語(yǔ)法 表連接 + 條件連接

66、select ename, dname from emp join dept on(emp.deptno = dept.deptno); -- 新語(yǔ)法

67、select ename,dname from emp join dept using(deptno); --與66題的寫(xiě)法是一樣的,但是不推薦使用using : 假設(shè)條件太多

--------------------------------------/非等值連接------------------------------------------/

68、select ename,grade from emp e join salgrade s on(e.sal between s.losal and s.hisal); --兩張表的連接 此種寫(xiě)法比用where更清晰

69、select ename, dname, grade from emp e

join dept d on(e.deptno = d.deptno)

join salgrade s on (e.sal between s.losal and s.hisal)

where ename not like '_A%'; --三張表的連接

70、select e1.ename, e2.ename from emp e1 join emp e2 on(e1.mgr = e2.empno); --自連接第二種寫(xiě)法,同62

71、select e1.ename, e2.ename from emp e1 left join emp e2 on(e1.mgr = e2.empno); --左外連接 把左邊沒(méi)有滿足條件的數(shù)據(jù)也取出來(lái)

72、select ename, dname from emp e right join dept d on(e.deptno = d.deptno); --右外連接

73、select deptno, avg_sal, grade from (select deptno, avg(sal) avg_sal from emp group by deptno) t join salgrade s on (t.avg_sal between s.losal and s.hisal);--求每個(gè)部門(mén)平均薪水的等級(jí)

74、select ename from emp where empno in (select mgr from emp); -- 在表中搜索那些人是經(jīng)理

75、select sal from emp where sal not in(select distinct e1.sal from emp e1 join emp e2 on(e1.sal e2.sal)); -- 面試題 不用組函數(shù)max()求薪水的最大值

76、select deptno, max_sal from

(select avg(sal) max_sal,deptno from emp group by deptno)

where max_sal =

(select max(max_sal) from

(select avg(sal) max_sal,deptno from emp group by deptno)

);--求平均薪水最高的部門(mén)名稱(chēng)和編號(hào)。

77、select t1.deptno, grade, avg_sal from

(select deptno, grade, avg_sal from

(select deptno, avg(sal) avg_sal from emp group by deptno) t

join salgrade s on(t.avg_sal between s.losal and s.hisal)

) t1

join dept on (t1.deptno = dept.deptno)

where t1.grade =

(

select min(grade) from

(select deptno, grade, avg_sal from

(select deptno, avg(sal) avg_sal from emp group by deptno) t

join salgrade s on(t.avg_sal between s.losal and s.hisal)

)

)--求平均薪水等級(jí)最低的部門(mén)的名稱(chēng) 哈哈 確實(shí)比較麻煩

78、create view v$_dept_avg_sal_info as

select deptno, grade, avg_sal from

(select deptno, avg(sal) avg_sal from emp group by deptno) t

join salgrade s on(t.avg_sal between s.losal and s.hisal);

--視圖的創(chuàng)建,一般以v$開(kāi)頭,但不是固定的

79、select t1.deptno, grade, avg_sal from v$_dept_avg_sal_info t1

join dept on (t1.deptno = dept.deptno)

where t1.grade =

(

select min(grade) from

v$_dept_avg_sal_info t1

)

)--求平均薪水等級(jí)最低的部門(mén)的名稱(chēng) 用視圖,能簡(jiǎn)單一些,相當(dāng)于Java中方法的封裝

80、---創(chuàng)建視圖出現(xiàn)權(quán)限不足時(shí)候的解決辦法:

conn sys/admin as sysdba;

--顯示:連接成功 Connected

grant create table, create view to scott;

-- 顯示: 授權(quán)成功 Grant succeeded

81、-------求比普通員工最高薪水還要高的經(jīng)理人的名稱(chēng) -------

select ename, sal from emp where empno in

(select distinct mgr from emp where mgr is not null)

and sal

(

select max(sal) from emp where empno not in

(select distinct mgr from emp where mgr is not null)

)

82、---面試題:比較效率

select * from emp where deptno = 10 and ename like '%A%';--好,將過(guò)濾力度大的放在前面

select * from emp where ename like '%A%' and deptno = 10;

83、-----表的備份

create table dept2 as select * from dept;

84、-----插入數(shù)據(jù)

insert into dept2 values(50,'game','beijing');

----只對(duì)某個(gè)字段插入數(shù)據(jù)

insert into dept2(deptno,dname) values(60,'game2');

85、-----將一個(gè)表中的數(shù)據(jù)完全插入另一個(gè)表中(表結(jié)構(gòu)必須一樣)

insert into dept2 select * from dept;

86、-----求前五名員工的編號(hào)和名稱(chēng)(使用虛字段rownum 只能使用 或 = 要使用 必須使用子查詢)

select empno,ename from emp where rownum = 5;

86、----求10名雇員以后的雇員名稱(chēng)--------

select ename from (select rownum r,ename from emp) where r 10;

87、----求薪水最高的前5個(gè)人的薪水和名字---------

select ename, sal from (select ename, sal from emp order by sal desc) where rownum =5;

分位數(shù)如何計(jì)算

分位數(shù)的計(jì)算步驟如下:

第一步,要知道什么是分位數(shù)。分位數(shù)也叫分位點(diǎn),是指將一個(gè)隨機(jī)變量的概率分布范圍分為幾個(gè)等份的數(shù)值點(diǎn)。常用的有中位數(shù)(即二分位數(shù))、四分位數(shù)、百分位數(shù)等。

第二步,生活中,最常見(jiàn)有中位數(shù)(也就是二分位數(shù))、四分位數(shù)、百分位數(shù)等等。

第三步,對(duì)于二分位數(shù),也就是中位數(shù),可以通過(guò)把所有觀察值高低排序后,找出正中間的一個(gè)作為中位數(shù)。注意觀察法適用于有限的數(shù)集。

第四步,如果觀察值有偶數(shù)個(gè),則中位數(shù)不唯一,通常取最中間的兩個(gè)數(shù)值的平均數(shù)作為中位數(shù),即二分位數(shù)。

第五步,四分位數(shù)的計(jì)算方法就是即把所有數(shù)值由小到大排列并分成四等份,處于三個(gè)分割點(diǎn)位置的數(shù)值就是四分位數(shù)。

第六步,對(duì)于四分位數(shù)我們也要區(qū)分好第一四分位數(shù)、第二四分位數(shù)、第三分位數(shù)等。

注意二分位數(shù)使用觀察法時(shí),適用于數(shù)集有限,并數(shù)量較少。

分位數(shù)回歸思想的提出至今已經(jīng)有近30多年了,經(jīng)過(guò)這近30多年的發(fā)展,分位數(shù)回歸在理論和方法上都越來(lái)越成熟,并被廣泛應(yīng)用于多種學(xué)科中。它對(duì)于實(shí)際問(wèn)題能提供更加全面的分析,無(wú)論是線性模型還是非線性模型,分位數(shù)回歸都是一種很好的工具,它對(duì)一般回歸模型做了有益的補(bǔ)充。

如何求分位數(shù)

四分位數(shù)的定義

四分位數(shù)(Quartile)是指在統(tǒng)計(jì)學(xué)中把所有數(shù)值由小到大排列并分成四等份,處于三個(gè)分割點(diǎn)位置的數(shù)值。多應(yīng)用于統(tǒng)計(jì)學(xué)中的箱線圖繪制。第一四分位數(shù) (Q1),又稱(chēng)“較小四分位數(shù)”,等于該樣本中所有數(shù)值由小到大排列后第25%的數(shù)字。第二四分位數(shù) (Q2),又稱(chēng)“中位數(shù)”,等于該樣本中所有數(shù)值由小到大排列后第50%的數(shù)字。 第三四分位數(shù) (Q3),又稱(chēng)“較大四分位數(shù)”,等于該樣本中所有數(shù)值由小到大排列后第75%的數(shù)字。第三四分位數(shù)與第一四分位數(shù)的差距又稱(chēng)四分位距。

四分位數(shù)實(shí)例

實(shí)例1

數(shù)據(jù)總量: 6, 47, 49, 15, 42, 41, 7, 39, 43, 40, 36

由小到大排列的結(jié)果: 6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49

一共11項(xiàng)

Q1 的位置=(11+1) × 0.25=3, Q2 的位置=(11+1)× 0.5=6, Q3的位置=(11+1) × 0.75=9

Q1 = 15,

Q2 = 40,

Q3 = 43

請(qǐng)教oracle 四分位數(shù)算法的函數(shù)

SQL CREATE TABLE sales (

2 product_id NUMBER ( 6 ) ,

3 cid NUMBER,

4 time_id DATE,

5 sold NUMBER ( 3 ) ,

6 amount NUMBER ( 10 , 2 ) ,

7 cost NUMBER ( 10 , 2 )

8 ) ;

Table created.

SQL

SQL CREATE TABLE products (

2 product_id NUMBER ( 6 ) ,

3 name VARCHAR2 ( 50 ) ,

4 subcategory VARCHAR2 ( 50 ) ,

5 category VARCHAR2 ( 50 ) ,

6 min_price NUMBER ( 8 , 2 )

7 ) ;

Table created.

SQL

SQL

SQL

SQL select b.subcategory, sum ( a.sold ) ,ntile ( 4 ) over ( ORDER BY SUM ( a.sold ) desc ) as quartile

2 from sales a, products b

3 where a.product_id = b.product_id

4 and to_char ( a.time_id, 'yy yy-mm ') = '20 01 - 06 '

5 group by b.subcategory;

no rows selected

SQL

SQL

SQL drop table sales;

Table dropped.

SQL

SQL drop table products;

Table dropped.

SQL

oracle中的sql求總分前三名

可以用row_number來(lái)查詢。

1、創(chuàng)建數(shù)據(jù)表,插入數(shù)據(jù):

create?table?sc

(id?int,

name?varchar(20),

class?varchar(20),

score?int);

insert?into?sc?values?(1,'badkano','一年一班',100);

insert?into?sc?values?(2,'百度知道團(tuán)長(zhǎng)','一年一班',99);

insert?into?sc?values?(3,'du小短','一年一班',95);

insert?into?sc?values?(4,'du小小動(dòng)','一年一班',97);

insert?into?sc?values?(5,'du小智','一年一班',80);

insert?into?sc?values?(6,'呂布','一年二班',67);

insert?into?sc?values?(7,'趙云','一年二班',90);

insert?into?sc?values?(8,'典韋','一年二班',89);

insert?into?sc?values?(9,'關(guān)羽','一年二班',70);

insert?into?sc?values?(10,'馬超','一年二班',98);

commit;

2、查詢分?jǐn)?shù)的前三名,可用以下語(yǔ)句:

select?*?from?

(select?row_number()?over?(order?by?score?desc)?rn,sc.*?from?sc)

where?rn=3;

3、結(jié)果顯示:

標(biāo)題名稱(chēng):oracle中如何求分位 oracle 四分位數(shù)
標(biāo)題鏈接:http://www.muchs.cn/article16/hjegdg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、做網(wǎng)站微信公眾號(hào)、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、云服務(wù)器、外貿(mào)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)