group by,order by ,having

          group by

          -- 使用 group by 語句查詢

          select count(studName) from student_1 group by study

          select count(uname) from userluo group by age;

          ?

          ?

          根據某一個字段進行分組

          select age,count(*) from userluo group by age;

          select uname,count(*) from userluo group by uname;

          ?

          ? 矛盾。。。。。

          ?


          盡管 deptno deptname 是一一對應的,但 group by 不知道。。。按照語法來檢查。。。

          ?Group by 后面也可以有多個字段,但是要求和前面一致。。。。。。。。

          ?

          ?

          ?

          -- 單列分組

          -- 顯示每個部門的平均工資和最高工資

          Select deptno,avg(sal),max(sal) from emp

          group by deptno;

          ?

          -- 多列分組

          -- 顯示每個部門、每種崗位的平均工資和最高工資

          Select deptno,job,avg(sal),max(sal) from emp

          group by deptno,job;?-- 注意: deptno job 完全相同才顯示一條記錄。

          ?

          ?

          ?

          ?

          ?

          Having group by 配套使用。。。

          可以在 group 分組以后再過濾,

          select age,count(*) from userluo group by age having count(*)<2;

          -- 使用 having 語句

          select trim(studName),count(*) from student_1 group by trim(studName) having count(*)=2;

          select count(*) studName from student_1 group by studName having count(*)=2;

          ?

          order by

          -- 使用 order by 語句 ,desc 是降序排列, asc 是升序排列 , 默認為升序排列

          select * from student_1 order by age desc;

          select * from student_1 order by age sname desc; 先按 age 排列,相同的 age 再按 sname 排列,

          posted on 2009-03-28 14:26 luofeng225 閱讀(3573) 評論(0)  編輯  收藏 所屬分類: Oracle


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2009年3月>
          22232425262728
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          導航

          統計

          公告

          我曾經聽到這么一個故事: 一個年輕的程序員問一個老程序員(一個比較牛逼的公司的CTO) 年輕程序員: 你為什么這么牛X., 就好像沒有你不會的。老程序員: 積累的。年輕程序員: 怎么才能積累到您的程度呢。我每天都在積累。但是似乎都沒有感覺到進步。老程序員: 我從20歲開始做到了一件事情,直到今天,而且盡可能地保證不間斷。年輕程序員: 到底是什么? 老程序員: 我每天保證自己有2個小時在學習新的東西。

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          相冊

          收藏夾

          Java Website

          java技術博客

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 无锡市| 治县。| 卓尼县| 扬中市| 望谟县| 望奎县| 广州市| 封丘县| 兰州市| 合川市| 梁平县| 定陶县| 吕梁市| 霸州市| 富裕县| 镇赉县| 赤水市| 三门峡市| 五常市| 晴隆县| 朔州市| 离岛区| 凤翔县| 枣庄市| 宁德市| 沙湾县| 陆河县| 巨鹿县| 盐池县| 芜湖市| 铜川市| 鞍山市| 郑州市| 顺义区| 肥城市| 翁源县| 香格里拉县| 定襄县| 高台县| 玉门市| 永顺县|