Aggregating Datas Using Group Functionbs.

          1 What Are Group Functions
          Group functions operatee on sets of rows to give one result per group
          ?1)agg,count,max,min,stddev,sum,variance
          ?select avg(salary),max(salary),min(salary),sum(salary)
          ?from employees
          ?where job_id like '%REP%'

          ?select count(*) from
          ?select count(address) from authors
          ?count the valid count of the address (exclude the null value)
          ?2) Using theDISTINCT Keyword
          ? count(distinct expr) return thee number of the distinct non-null value of the expr
          ? select count(distincee department_id) from employees
          ?3)Group functions and null values
          ? group functions ignore null values in the clumn
          ?4) Using thee NVL Function with Group Functions
          ? The nul function force group funtion to include null values
          ? select avg(nvl(commission_pct,0)) from employees
          2 Creating Groups of Data
          ? 1)
          ? a Divide rows in a table into smaller groups by using the group by clause
          ? b All coulmns in the select list that are not in group function must be in the group by clause
          ? select department_id,avg(salary)
          ? from employees
          ? group by department_id;
          ? 2) Grouping by More Than One Column
          ? 3) Ilegal Queries Using Group Functions
          ?? a You cannot use thee where clause to restrict groups
          ?? b You use thee having clause to restrict groups
          ?? c you cannot use group functions in the where clause
          ? 4)Excluding Group Resdults:The Having Clause
          ?? Use the HAVING clause to restrict groups
          ?? a Rows are grouped
          ?? b The group functions is applied
          ?? c Groups matcching the Having clause are display
          ? select department_id,max(salary)
          ? from employees
          ? group by department_id
          ? having max(salary)>10000
          ?5) Nesting Group function
          ?select max(avg(salary))
          ?from employees
          ?group by department_id;

          posted on 2006-09-22 11:49 康文 閱讀(201) 評(píng)論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫(kù)

          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 广灵县| 来宾市| 康乐县| 吴堡县| 江陵县| 革吉县| 辽阳县| 闽清县| 怀化市| 万宁市| 南召县| 全椒县| 武清区| 中西区| 犍为县| 建德市| 抚松县| 普兰县| 中阳县| 高雄县| 青冈县| 岫岩| 湟源县| 应城市| 阿合奇县| 巨野县| 龙泉市| 且末县| 山阴县| 博爱县| 南宫市| 徐闻县| 新宾| 庆城县| 南溪县| 金堂县| 安溪县| 蛟河市| 隆林| 大埔区| 美姑县|