MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

DATABASE & SQL/PLSQL

Using GROUP BY Clause
Previous Home Next

Group clause summarize the result set in to a groups defined in the query using aggregate function.

SELECT  'max'=MAX (discount)
FROM  discountsSELECT column1, column2, ... column_n, aggregate_function (expression)
FROM table_name
WHERE conditions
GROUP BY ALL column1, column2, ... column_n
SELECT  'max'=MAX (discount)
FROM  discountsSELECT column1, column2, ... column_n, aggregate_function (expression)
FROM table_name
WHERE conditions
GROUP BY ALL column1, column2, ... column_n

expressions: describe the column name (s) or expressions on which the result set of the SELECT statement is to be grouped.

ALL is a keyword used to include those groups that do not meet the search condition.

Example

SELECT type, 'avg'=AVG(advance)
FROM titles
WHERE type LIKE 'b%'
GROUP BY ALL type

Output

typeRange
business 5000.0000
mod_cook NULL
popular_comp NULL
psychology NULL
trad_cook NULL
UNDECIDED NULL

Return all type from table but the 'avg' display only those type which started with ' b'. Means this keyword used to display all groups, including those exclude from WHERE clause. The ALL keyword is meaningful for those query that contain WHERE clause.

Example

SELECT  type,'pub Id'=pub_id, 'avg'=AVG (price)
FROM  titles
GROUP BY  type,pub_id

Return the 'type' and 'pub Id' and 'avg' , which calculated from titles table.

Example

SELECT type, 'avg'=AVG(advance)
FROM titles
WHERE title_id IN ('BU1032','PC1035')
GROUP BY ALL type

 

Output

typeRange
business 5000.0000
mod_cook NULL
popular_comp 7000.0000
psychology NULL
trad_cook NULL
UNDECIDED NULL
Previous Home Next