0% found this document useful (0 votes)
54 views2 pages

Syntax: Select (Columns List) From Tablename Group by Column Name

1) The GROUP BY clause is used to divide a table into subgroups based on a specific column. 2) The HAVING clause is used to evaluate conditions for each group created by the GROUP BY clause. 3) Special functions like COUNT(), DISTINCT() are used to count rows, display distinct values for a column respectively. COUNT() counts all non-null values while DISTINCT() considers one null value.

Uploaded by

tab12345
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

Syntax: Select (Columns List) From Tablename Group by Column Name

1) The GROUP BY clause is used to divide a table into subgroups based on a specific column. 2) The HAVING clause is used to evaluate conditions for each group created by the GROUP BY clause. 3) Special functions like COUNT(), DISTINCT() are used to count rows, display distinct values for a column respectively. COUNT() counts all non-null values while DISTINCT() considers one null value.

Uploaded by

tab12345
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

GROUP BY CLAUSE: This clause is used to divide the table into number of subgroups based on a specific column.

Syntax: SELECT {COLUMNS LIST} FROM TABLENAME GROUP BY COLUMN NAME E.g.: SELECT DEPTNO !"# $S"L% "S &'S"L !'N $S"L% "S LOS"L S(! $S"L% "S TOTS"L ")* $S"L% "S ")*S"L +,O! E!P *,O(P -. DEPTNO DEPTNO /0 30 HISAL /1000 30000 LOSAL 1000 1000 TOTSAL 20000 31000 AVGSAL /0000 /3100

HAVING CLAUSE: This clause is used to evaluate a condition 4ith group b5 clause. *enerall5 for evaluating conditions 4e 4ill use 6&E,E clause but 4here clause does not support b5 group b5 clause. Syntax: SELECT STATEMENT GROUP BY COLUMN NAME [HAVING CONDITION] E.g.: SELECT DEPTNO !"# $S"L% "S &'S"L !'N $S"L% "S LOS"L S(! $S"L% "S TOTS"L ")* $S"L% "S ")*S"L +,O! E!P *,O(P -. DEPTNO &")'N* ")* $S"L%7/0000 DEPTNO 30 HISAL 30000 LOSAL 1000 TOTSAL 31000 AVGSAL /3100

SPECIAL FUNCTIONS COUNT( ): Count function counts the number of ro4s available for a specific column. 't counts onl5 values e8cept N(LL values. 't is associated 4ith three parameters. CO(NT $9% CO(NT $Column Name% E.g.: SELECT CO(NT $9% "S NO:O+:,O6S +,O! E!P NO:O+:,O6S 1

E.g.: SELECT CO(NT $DEPTNO% "S NO:O+:,O6S +,O! E!P NO:O+:,O6S 1 DISTINCT ( ): This function displa5s the different values available for a specific column. 't considers one N(LL value. E.g.: SELECT D'ST'NCT $DEPTNO% "S D'++:)"L(ES +,O! E!P D'++:)"L(ES /0 30 E.g.: SELECT CO(NT $D'ST'NCT$ DEPTNO%% "S NO:O+:,O6S +,O! E!P NO:O+:,O6S 3 Note: CO(NT function does not count the ro4s of the column 4hose data t5pe is -'*'NT 'n such situations 4e have to use COUNT_BIG function

You might also like