SlideShare a Scribd company logo
1 of 4
CLAUSES: 
There are totally 4 types of clauses are present in SQLSERVER those are 
1. GROUPBY 
2. ORDERBY 
3. WHERE 
4. HAVING 
Create Database Practice DB 
GO 
Create Table EMPLOYEE 
Go 
Insert into EMPLOYEE values (EName VARCHAR (10), SAL VARCHAR (MAX), JOB VARCHAR (15), 
DEPTNO INT) 
GO 
insert DEPARTMENT values(‘RAGHU’,3000,’CLERK’,10), (‘SATISH’,80000,’MANAGER’,10), 
(‘KIRAN’,9000,’CLERK’,30), (‘RAVI’,30000,’ACCOUNTANT’,30), (‘ASHOK’,2000,’MANAGER’,20), 
(‘PRABHA’,17000,’ACCOUNTANT’,20), (‘RADHA’,13000,’CLERK’,20) 
GO 
ORDERBY: 
It is used to display Records in the table in ascending order or descending order 
SYNTAX: 
SELECT statement 
ORDERBY<coloumn_name> [DESC] 
EXAMPLE QUERIES: 
TO CREATE DUPLICATE TABLE ANS STORE SALARIES IN ASCENDING 
ORDER 
SYNTAX:
SELECT * INTO<DUPLICATE_TABLE> 
FROM<OLD_TABLE> 
SELECT * INTO EMPLIST 
FROM EMPLOYEE ORDERBY SAL 
IN SQLSERVER 2012 duplicate table will not work. 
TO GET NAMES IN ALPHABETICAL ORDER 
SELECT * FROM EMPLOYEE 
ORDER BY ENAME 
TO GET SALARIES IN ASCENDING ORDER 
SELECT * FROM EMPLOYEE 
ORDER BY SAL 
TO GET SALARIES IN DESCENDING ORDER 
SELECT * FROM EMPLOYEE 
ORDER BY SAL DESC 
TO GET SALARIES IN ASCENDING ORDER WITH DEPTNO 
SELECT * FROM EMPLOYEE 
WHERE DEPTNO=10 
ORDER BY SAL 
TO DISPLAY SALARIES BASED ON JOB 
SELECT * FROM EMPLOYEE 
ORDER BY JOB.SAL 
TO GET THREE HIGHEST SALARIES FROM EMPLOYEE TABLE 
SELECT TOP3 SAL FROM EMPLOYEE 
ORDERBY SAL DESC 
TO GET LAST 3 RECORDS FROM EMPLOYEE TABLE 
SELECT * FROM EMPLOYEE 
ORDER BY ENO
OFFSET 3 ROWS 
FETCH NEXT 3 ROWS ONLY 
NOTE:FETCH AND OFFSET COMMANDS WILL WORK ONLY IN SQLSERVER 2012. 
TO GET SALARIES IN ASCENDING ORDER BASED ON THE GIVEN COLOUMN INDEX 
VALUE 
SELECT * FROM EMPLOYEE 
ORDER BY 6 
GROUPBY: 
1. Ii is used to group duplicate values or similar values existing in the columns of the table 
2. With GROUPBY statement GROUP OR AGGRIGATE functions will be used. They are used to work on 
multiple values or multiple rows in the table. 
The functions are SUM(),AVG(),MAX(),M IN(),COUNT (),STDEV(),VA R()…etc. 
SYNATAX: 
SELECT STATEMENT 
GROUPBY<COLOUMN NAME> 
[HAVING CLAUSE] 
TO GET COUNT OF EMPLOYEE IN EACH DEPARTMENNT 
SELECT DEPTNO,COUNT(*)FROM EMPLOYEE 
GROUP BY DEPTNO 
OR 
SELECT DEPTNO,COUNT(JOB)no_of_emp(TEMPORARY COLUMN NAME USED) HERE FROM 
EMPLOYEE 
GROUPBY DEPTNO
TO GET COUNT OF EMPLOYEES WITH DEPTNO 10 
SELECT DEPTNO,COUNT(DEPTNO) FROM EMPLOYEE 
WHERE DEPT NO=10 
GROUPBY DEPTNO 
OR 
HAVING DEPTNO=10 
TO GET COUNT OF EMPLOYEES ONLY WHEN THE COUNT IS GREATER THAN 3 
SELECT DEPTNO,COUNT(DEPTNO)FROM EMPLOYEE 
GROUPBY DEPTNO 
HAVING COUNT(DEPTNO)>3 
TO GET COUNT OF EMPLOYEES IN EACH JOB 
SELECT JOB,COUNT(JOB)FROM EMPLOYEE 
GROUPBY JOB 
TO GET HIGHEST SALARY FROM EACH DEPARTEMENT 
SELECT DEPTNO,MAX(SAL) FROM EMPLOYEE 
GROUPBY DEPTNO 
TO GET HIGHEST SALARY FROM EACH JOB 
SELECT JOB,MAX(SAL) FROM EMPLOYEE 
GROUPBY JOB 
TO GET HIGHEST SALARY FROM EACH JOB AND DISPLAY SALARIES IN 
ASCENDING ORDER 
SELECT JOB,MAX(SAL) FROM EMPLOYEE 
GROUPBY JOB 
ORDERBY MAX(SAL) 
OR 
SELECT JOB,MAX(SAL) FROM EMPLOYEE 
GROUPBY JOB 
ORDERBY SAL

More Related Content

What's hot (20)

Complex queries in sql
Complex queries in sqlComplex queries in sql
Complex queries in sql
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with output
 
Les18
Les18Les18
Les18
 
Array menu
Array menuArray menu
Array menu
 
Sql queires
Sql queiresSql queires
Sql queires
 
Performante Java Enterprise Applikationen trotz O/R-Mapping
Performante Java Enterprise Applikationen trotz O/R-MappingPerformante Java Enterprise Applikationen trotz O/R-Mapping
Performante Java Enterprise Applikationen trotz O/R-Mapping
 
Structured query language(sql)
Structured query language(sql)Structured query language(sql)
Structured query language(sql)
 
PL/SQL Blocks
PL/SQL BlocksPL/SQL Blocks
PL/SQL Blocks
 
SQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftjSQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftj
 
array implementation
 array implementation array implementation
array implementation
 
My Sql
My Sql My Sql
My Sql
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testers
 
Sql wksht-5
Sql wksht-5Sql wksht-5
Sql wksht-5
 
Use shop
Use shopUse shop
Use shop
 
SQL BASIC QUERIES
SQL  BASIC QUERIES SQL  BASIC QUERIES
SQL BASIC QUERIES
 

Viewers also liked (18)

Asp.net
Asp.netAsp.net
Asp.net
 
CRM and ERP
CRM and ERPCRM and ERP
CRM and ERP
 
Triggers
TriggersTriggers
Triggers
 
collections
 collections collections
collections
 
Joins
JoinsJoins
Joins
 
MOM on BA
MOM on BAMOM on BA
MOM on BA
 
Built in functions
Built in functionsBuilt in functions
Built in functions
 
MOM on activity diagram
MOM on activity diagramMOM on activity diagram
MOM on activity diagram
 
UML Diagrams
UML DiagramsUML Diagrams
UML Diagrams
 
access modifiers
access modifiersaccess modifiers
access modifiers
 
Tools used by ba
Tools used by baTools used by ba
Tools used by ba
 
Bill Gates
Bill GatesBill Gates
Bill Gates
 
exception handling
 exception handling exception handling
exception handling
 
Business Analyst
Business AnalystBusiness Analyst
Business Analyst
 
Generics collections
Generics collectionsGenerics collections
Generics collections
 
System development life cycle
System development life cycleSystem development life cycle
System development life cycle
 
Business Analyst Documentation
Business Analyst DocumentationBusiness Analyst Documentation
Business Analyst Documentation
 
Business analyst ppt
Business analyst pptBusiness analyst ppt
Business analyst ppt
 

Similar to Clauses

Similar to Clauses (20)

Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
12. Basic SQL Queries (2).pptx
12. Basic SQL Queries  (2).pptx12. Basic SQL Queries  (2).pptx
12. Basic SQL Queries (2).pptx
 
Complex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxComplex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptx
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
Les04
Les04Les04
Les04
 
SQL
SQLSQL
SQL
 
Les04
Les04Les04
Les04
 
Les05
Les05Les05
Les05
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
sql language
sql languagesql language
sql language
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
Dynamic websites lec2
Dynamic websites lec2Dynamic websites lec2
Dynamic websites lec2
 
Exploring collections with example
Exploring collections with exampleExploring collections with example
Exploring collections with example
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
 
Module03
Module03Module03
Module03
 
Les17
Les17Les17
Les17
 
DOODB_LAB.pptx
DOODB_LAB.pptxDOODB_LAB.pptx
DOODB_LAB.pptx
 
Sql server ___________session 3(sql 2008)
Sql server  ___________session 3(sql 2008)Sql server  ___________session 3(sql 2008)
Sql server ___________session 3(sql 2008)
 

More from Yaswanth Babu Gummadivelli (17)

Presentation on BA
Presentation on BAPresentation on BA
Presentation on BA
 
ERP
ERPERP
ERP
 
Ba -content
Ba -contentBa -content
Ba -content
 
E commerce use case documentation.
E commerce use case documentation.E commerce use case documentation.
E commerce use case documentation.
 
Constructors
Constructors Constructors
Constructors
 
array
array array
array
 
Use case for atm
Use case for atmUse case for atm
Use case for atm
 
use case diagramHospital managment system
use case diagramHospital managment systemuse case diagramHospital managment system
use case diagramHospital managment system
 
Activity diagram for ticket vending machine
Activity diagram for ticket vending machineActivity diagram for ticket vending machine
Activity diagram for ticket vending machine
 
Extreme programming
Extreme programmingExtreme programming
Extreme programming
 
Agile model
Agile model Agile model
Agile model
 
Reflection
ReflectionReflection
Reflection
 
Exceptions in SQL Server
Exceptions in SQL ServerExceptions in SQL Server
Exceptions in SQL Server
 
Views
ViewsViews
Views
 
Subqueries
SubqueriesSubqueries
Subqueries
 
Set operators
Set operatorsSet operators
Set operators
 
Indexes
IndexesIndexes
Indexes
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 

Clauses

  • 1. CLAUSES: There are totally 4 types of clauses are present in SQLSERVER those are 1. GROUPBY 2. ORDERBY 3. WHERE 4. HAVING Create Database Practice DB GO Create Table EMPLOYEE Go Insert into EMPLOYEE values (EName VARCHAR (10), SAL VARCHAR (MAX), JOB VARCHAR (15), DEPTNO INT) GO insert DEPARTMENT values(‘RAGHU’,3000,’CLERK’,10), (‘SATISH’,80000,’MANAGER’,10), (‘KIRAN’,9000,’CLERK’,30), (‘RAVI’,30000,’ACCOUNTANT’,30), (‘ASHOK’,2000,’MANAGER’,20), (‘PRABHA’,17000,’ACCOUNTANT’,20), (‘RADHA’,13000,’CLERK’,20) GO ORDERBY: It is used to display Records in the table in ascending order or descending order SYNTAX: SELECT statement ORDERBY<coloumn_name> [DESC] EXAMPLE QUERIES: TO CREATE DUPLICATE TABLE ANS STORE SALARIES IN ASCENDING ORDER SYNTAX:
  • 2. SELECT * INTO<DUPLICATE_TABLE> FROM<OLD_TABLE> SELECT * INTO EMPLIST FROM EMPLOYEE ORDERBY SAL IN SQLSERVER 2012 duplicate table will not work. TO GET NAMES IN ALPHABETICAL ORDER SELECT * FROM EMPLOYEE ORDER BY ENAME TO GET SALARIES IN ASCENDING ORDER SELECT * FROM EMPLOYEE ORDER BY SAL TO GET SALARIES IN DESCENDING ORDER SELECT * FROM EMPLOYEE ORDER BY SAL DESC TO GET SALARIES IN ASCENDING ORDER WITH DEPTNO SELECT * FROM EMPLOYEE WHERE DEPTNO=10 ORDER BY SAL TO DISPLAY SALARIES BASED ON JOB SELECT * FROM EMPLOYEE ORDER BY JOB.SAL TO GET THREE HIGHEST SALARIES FROM EMPLOYEE TABLE SELECT TOP3 SAL FROM EMPLOYEE ORDERBY SAL DESC TO GET LAST 3 RECORDS FROM EMPLOYEE TABLE SELECT * FROM EMPLOYEE ORDER BY ENO
  • 3. OFFSET 3 ROWS FETCH NEXT 3 ROWS ONLY NOTE:FETCH AND OFFSET COMMANDS WILL WORK ONLY IN SQLSERVER 2012. TO GET SALARIES IN ASCENDING ORDER BASED ON THE GIVEN COLOUMN INDEX VALUE SELECT * FROM EMPLOYEE ORDER BY 6 GROUPBY: 1. Ii is used to group duplicate values or similar values existing in the columns of the table 2. With GROUPBY statement GROUP OR AGGRIGATE functions will be used. They are used to work on multiple values or multiple rows in the table. The functions are SUM(),AVG(),MAX(),M IN(),COUNT (),STDEV(),VA R()…etc. SYNATAX: SELECT STATEMENT GROUPBY<COLOUMN NAME> [HAVING CLAUSE] TO GET COUNT OF EMPLOYEE IN EACH DEPARTMENNT SELECT DEPTNO,COUNT(*)FROM EMPLOYEE GROUP BY DEPTNO OR SELECT DEPTNO,COUNT(JOB)no_of_emp(TEMPORARY COLUMN NAME USED) HERE FROM EMPLOYEE GROUPBY DEPTNO
  • 4. TO GET COUNT OF EMPLOYEES WITH DEPTNO 10 SELECT DEPTNO,COUNT(DEPTNO) FROM EMPLOYEE WHERE DEPT NO=10 GROUPBY DEPTNO OR HAVING DEPTNO=10 TO GET COUNT OF EMPLOYEES ONLY WHEN THE COUNT IS GREATER THAN 3 SELECT DEPTNO,COUNT(DEPTNO)FROM EMPLOYEE GROUPBY DEPTNO HAVING COUNT(DEPTNO)>3 TO GET COUNT OF EMPLOYEES IN EACH JOB SELECT JOB,COUNT(JOB)FROM EMPLOYEE GROUPBY JOB TO GET HIGHEST SALARY FROM EACH DEPARTEMENT SELECT DEPTNO,MAX(SAL) FROM EMPLOYEE GROUPBY DEPTNO TO GET HIGHEST SALARY FROM EACH JOB SELECT JOB,MAX(SAL) FROM EMPLOYEE GROUPBY JOB TO GET HIGHEST SALARY FROM EACH JOB AND DISPLAY SALARIES IN ASCENDING ORDER SELECT JOB,MAX(SAL) FROM EMPLOYEE GROUPBY JOB ORDERBY MAX(SAL) OR SELECT JOB,MAX(SAL) FROM EMPLOYEE GROUPBY JOB ORDERBY SAL