字段解釋:
xh:學(xué)號(hào)
xh:姓名
nl:年齡
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供偏關(guān)企業(yè)網(wǎng)站建設(shè),專注與成都做網(wǎng)站、成都網(wǎng)站制作、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為偏關(guān)眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。
create table student(xh number,xm varchar2(4),nl int);
insert into student values(1,'A',21);
insert into student values(2,'B',21);
insert into student values(3,'A',21);
insert into student values(4,'A',21);
insert into student values(5,'A',21);
insert into student values(6,'C',21);
insert into student values(7,'B',21);
查看表
SQL> select * from student;
XH XM NL
---------- ------------ ----------
1 A 21
2 B 21
3 A 21
4 A 21
5 A 21
6 C 21
7 B 21
7 rows selected.
SQL>
問(wèn)題:查詢有重復(fù)的姓名
思路:使用count函數(shù)做統(tǒng)計(jì),如果count >1,說(shuō)明有重復(fù)
SQL> select xm,count(*) from student group by xm having(count(*) > 1);
XM COUNT(*)
------------ ----------
A 4
B 2
SQL>
問(wèn)題:查詢重復(fù)姓名學(xué)生的所有信息
*思路:select from student可以查看所有學(xué)生的信息,怎么查看重復(fù)的呢?上面我們已經(jīng)知道了有哪些是重復(fù)的名字,那么我們只需要判斷,哪些名字在重復(fù)的名字里面即可**
SQL> select * from student where xm in (select xm from student group by xm having(count(*) >1));
XH XM NL
---------- ------------ ----------
1 A 21
2 B 21
3 A 21
4 A 21
5 A 21
7 B 21
6 rows selected.
SQL>
網(wǎng)頁(yè)名稱:groupby練習(xí)
文章地址:http://aaarwkj.com/article36/gdsopg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、全網(wǎng)營(yíng)銷推廣、電子商務(wù)、軟件開(kāi)發(fā)、App設(shè)計(jì)、做網(wǎng)站
聲明:本網(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)