Exforsys.com
 
Home Tutorials Oracle 9i
 

Tutorial 4: SQL functions

 

Tutorial 4: SQL functions - Page 7

Page 7 of 7



Using  WHERE , GROUP BY , HAVING AND ORDER BY clauses together.


 


General form of  the SELECT statement is


         SELECT <column1, column2, . . .>
         FROM   <table1, table2, . . .>
         WHERE  <where clause>       
         GROUP BY <column1, column2, . . .>
         HAVING   <having clause>
         ORDER BY <column1, column2, . . .>


when all the above said clauses are used in a select query they need to appear in the order specified above, violation of which will lead to errors.



Q.  A query to display departments paid 500 or more and have 2 or less employess can be displayed as shown below


SQL >SELECT DEPTNO ,COUNT(*) , SUM(SAL) FROM EMP
  2      WHERE JOB = 'CLERK'
  3       GROUP BY DEPTNO
  4       HAVING SUM(SAL) >=500 AND COUNT(*) < 2
  5       ORDER BY SUM(SAL) ASC;


    DEPTNO   COUNT(*)   SUM(SAL)
---------- ---------- ----------
        30          1        950
        10          1       1300




First Page: Tutorial 4: SQL functions


Read Next: Tutorial 5: Working with Multiple Tables



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape