Difference between revisions of "SYNTAX FOR GROUP HAVING ORDER BY"

From rbachwiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
SELECT ... AGRIGATEDFUNCTION()
<PRE>SELECT ... AGRIGATEDFUNCTION()
FROM TABLE1, ...
FROM TABLE1, ...
WHERE < CONDITION>
WHERE < CONDITION>
GROUP BY COL1, COL2...
GROUP BY COL1, COL2...
HAVING <AGG>
HAVING <AGG>
ORDER BY
ORDER BY</PRE>
''' THE HAVING CLAUSE ACTS ON AGG FUNCTIONS AND FILTERING GROUP BY OUTPUP'''


'''' FIND SALARY BASED ON EACH DEPARTMENT NUMBER'''
'''' FIND SALARY BASED ON EACH DEPARTMENT NUMBER'''
Line 25: Line 26:
  GROUP BY DEPTNO, JOBOFEMPLOYEE
  GROUP BY DEPTNO, JOBOFEMPLOYEE
  ORDER BY DEPTNO
  ORDER BY DEPTNO
   
  HAVING COUNT(*) >=3
ORDER BY DEPTNO


[[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]]
[[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]]

Latest revision as of 22:29, 18 November 2017

SELECT ... AGRIGATEDFUNCTION()
FROM TABLE1, ...
WHERE < CONDITION>
GROUP BY COL1, COL2...
HAVING <AGG>
ORDER BY

THE HAVING CLAUSE ACTS ON AGG FUNCTIONS AND FILTERING GROUP BY OUTPUP

' FIND SALARY BASED ON EACH DEPARTMENT NUMBER NOTE: THE SAME COLUMN USED THE THE SELECT STATEMENT "DEPTNO" SHOULD BE USED IN THE GROUP BY

SELECT DEPTNO, SUB(SALARY) "TOTAL SALARY"
FROM EMP
GROUP BY DEPTNO

DISPLAY THE NUMBER OF MALES AND FEMALES FROM EACH CITY ' TABLE > CUST > COLUMN GENDER, CITY

SELECT CITY, GENDER, COUNT(*) "NUMBER OF CUSTOMERS"
FROM CUST
GROUP BY CITY, GENDER

FIND NUMBER OF EMPLOYEES BASED ON EMPLOYEES BASED ON DEPTNO UNDER EACH DEPTNO JOBOFEMPLOYEE AND HAVING MORE THAN 3 COUNTS

SELECT DEPTNO, JOBOFEMPLOYEE, COUNT(*)
FROM EMP
GROUP BY DEPTNO, JOBOFEMPLOYEE
ORDER BY DEPTNO
HAVING COUNT(*) >=3
ORDER BY DEPTNO

Back To Top- Home - Category