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) 評論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫

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

          導航

          統(tǒng)計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 潞城市| 开原市| 钦州市| 沾化县| 哈密市| 五台县| 赞皇县| 沧州市| 南开区| 阿克陶县| 滕州市| 恭城| 无为县| 定襄县| 寿光市| 湾仔区| 齐河县| 阜新| 铜山县| 金川县| 正定县| 大丰市| 蒙山县| 海晏县| 勃利县| 阳信县| 若尔盖县| 阿克陶县| 岳池县| 合阳县| 铁岭县| 红桥区| 台湾省| 措美县| 固原市| 镇安县| 宜州市| 平和县| 平潭县| 留坝县| 衡阳市|