一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

select queries

 hildaway 2013-04-13

The SELECT query is the most often used query in any database. We will be referring tables from default schema/user SCOTT in Oracle.
The generalized select query looks like :

             SELECT [ DISTINCT| ALL]
                   { * | [columnName [ AS newColumnName ] ] ,
                    [columnName1 [ AS newColumnName1]],
                     .........,
                     .........,
                     }
             FROM tableName [ALIAS][,]
             [WHERE <condition>]
             [GROUP BY columnlist ] [HAVING <condition>]
             [ORDER BY columnlist]
 
We will start with simple query and then keep on building complex queries.

 1. Select all the details of the employee from emp table.

                  select * From emp;
                  Select records using multiple columns;
                  Select eno, ename, sal From emp;
                 Select records using multiple alias
                 Select eno as empno, ename as empname, sal as salary from emp;
2. Using functions to enhance alias
                Select count(sal) as totalsa From emp;
3. Derived or Computed fields: Columns values were manipulated as it gets retrived.
    a. Find the monthly salary of employee,( The salary stored is on Annum basis).
                 Select sal/12 From emp;
    b. Using Alias to decorate derived or computed fields. 
                Select sal/12 as montly_salary From emp;
    c. Calculate the sum of monthly salary and the commissions of the employee.
                Select ename, (sal/12)+nvl(comm,0) as monthsalwithcomm from emp;
4. Using Aggregate functions: Count,Min,Max,Sum,Avg.
   a. Find the number of rows in emp
                 Select count(*) From emp;
    b.Find the how many different Job profile are there in Employee table 
                Select Count(distinct job) From emp;
    c. Find out how many people were given commision  ( Count function does n't include null as it counts)
                Select Count(comm) From emp;
5. Select records from two tables;
                Select e.ename, d.deptno, e.sal From emp e, dept d;
6. Select records from two tables depending condition suppose where deptno of from both emp and dept mathes    
         Select e.ename, d.deptno, e.sal From emp e, dept d
              Where e.deptno=d.deptno;
7: Select records using between and;
          Select * From emp
              Where sal between 2000 and 3000
8. Select records using in;
          Select * From emp
              Where ename In ('SCOTT', 'WARD', 'ALLEN')
                     and sal In(1000, 2000, 3000,3200, 3300);
9: Select records using not in;
          Select * From emp
              Where ename Not In ('SCOTT','WARD', 'ALLEN')
10: Select records using null;
          Select * From emp
               Where comm Is null;
11:Select records using not null;
          Select * From emp Where comm Is Not null;
12:Select records using like;
           Select * From emp
                 Where ename Like'S%'
                        or ename Like 'sC__'
                        or ename Like 'A_L_N'
                        or ename Like '___L%';
13:Select records using not like;
           Select * From emp Where ename Not Like 'A%';
14:Select records using multiple conditions.
           Select * From emp
               Where comm is not null and ename not like(A%) and sal in (1000, 4000);
15:Select records using function;
           Select ename, sum(sal+comm), avg(sal) as avgssal as total  From emp
                Group by deptno;
16:Select records using order by;
           Select * From emp
               Order by sal Desc, empno,empname;
17:Select records using group by and having clause;
           Select deptno, sum(sal)
                Group by deptno Having deptno>20
18:Select with-in select;
          Select * From emp Where max(sal)< (Select max(sal) From emp);
          Select * From emp Where deptno=(select deptno From dept);
          Select *  From emp Where deptno Not In (Select deptno From dept);
19:create a table by selecting record from another table;
        Create Table emp2 as select * From emp;
20:Select records using exist;
        Select deptno From dept d
            where exists (Select * from emp e Where d.deptno=e.deptno);
21:Select sysdate;
         Select sysdate From dual
22:Select constraint name, constraint_type;
          Select constraint_name, constraint_type  From user_constraints
                where table_name='emp';
23:Select nextval, currval from sequence;
        Select emp_sequence.nextval From dual
        Select emp_sequence.currval from dual
24. Set Operators
 Set oepratros basically combine the result of two quesies into one. There queries are known as compound queries.
These are 4 set operators:
 (1) UNION: Returns all rows from either queries; no duplicate rows.
 (2) UNION ALL: Returns all rows from either query, including duplicates.
 (3) INTERSETCT: Returns distinct rows that are returned by both queries.
 (4) MINUS: Returns distinct rows that are returned by the first query but not returned by the second.
 
Example:

 
Query1:              Select ename  from emp where dept_id=40;
 This query returns result:     Alex, Peter, John, Richa
 
Query2:              Select ename  from emp where sal>=4000;
 This query returns result:      Aled, Peter, John, Chrish
 
Union: 
 (Select ename  from emp where dept_id=40) Union ( Select ename  from emp where sal>=4000)
 This will return result:           Alex, Peter,John, Richa, Aled, Chrish
 
UNION ALL:  
(Select ename  from emp where dept_id=40) Union All ( Select ename  from emp where sal>=4000)
 This will return:               Alex, Peter, John, Richa, Aled, Peter, John, Chrish
 
INTERSETCT: 
(Select ename  from emp where dept_id=40) INTERSETCT ( Select ename  from emp where sal>=4000)
 This will return:                       Peter, John
 
MINUS:
 (Select ename  from emp where dept_id=40)  MINUS  ( Select ename  from emp where sal>=4000)
 This will return:                       Alex, Richa

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    女生更色还是男生更色| 日本婷婷色大香蕉视频在线观看 | 九九九热视频免费观看| 性欧美唯美尤物另类视频| 欧美色欧美亚洲日在线| 日韩精品中文字幕亚洲| 日本午夜乱色视频在线观看| 大尺度剧情国产在线视频| 亚洲国产欧美精品久久| 丰满人妻熟妇乱又伦精另类视频| 99久久精品一区二区国产| 91欧美日韩一区人妻少妇| 又大又紧又硬又湿又爽又猛| 黄片三级免费在线观看| 91熟女大屁股偷偷对白| 九九热这里只有免费精品| 欧美激情中文字幕综合八区| 男女一进一出午夜视频| 女人精品内射国产99| 国产欧美高清精品一区| 儿媳妇的诱惑中文字幕| 国产又色又爽又黄又免费| 成人午夜免费观看视频| 成人午夜爽爽爽免费视频| 日本中文字幕在线精品| 欧美日韩一级黄片免费观看| 亚洲性生活一区二区三区| 天堂网中文字幕在线观看| 五月天综合网五月天综合网| 国产精品免费福利在线| 日韩高清中文字幕亚洲| 国产av熟女一区二区三区蜜桃| 国产精品久久女同磨豆腐| 国产精品一区二区三区黄色片| 日本人妻精品中文字幕不卡乱码| 亚洲专区中文字幕视频| 一区二区三区18禁看| 有坂深雪中文字幕亚洲中文| 麻豆国产精品一区二区| 人妻偷人精品一区二区三区不卡| 日韩中文字幕人妻精品|