Presentation is loading. Please wait.

Presentation is loading. Please wait.

GROUPING DATA FROM TABLE

Similar presentations


Presentation on theme: "GROUPING DATA FROM TABLE"— Presentation transcript:

1 GROUPING DATA FROM TABLE
Prepared By: Dr. Vipul Vekariya

2 Group by clause The group by clause is another section of the select statement. This optional clause used to group raw based on distinct values that exist for specified column. Group by clause create a data set, containing several set of records grouped together based on condition. Syntax: select <col 1>,<col 2>,<col N>, aggregate function(<expression>) from table name where <condition> group by<col 1>,<col 2>,<col N>;

3 Find out how many employee are there in each branch.
SELECT BRANCH_NO "Branch No.", COUNT(EMP_NO) "No. Of Employees“ FROM EMP_MSTR GROUP BY BRANCH_NO; TYPE "A/C Type", COUNT(ACCT_NO) "No. Of A/Cs" FROM ACCT_MSTR GROUP BY BRANCH_NO, TYPE;

4 Having Clause Having clause can be used in conjunction with the group by. Having is used for further filtering on group by clause. Find out the customer having more than one account in the bank. SELECT CUST_NO, COUNT(ACCT_FD_NO) "No. Of A/Cs Held" FROM ACCT_FD_CUST_DTLS WHERE ACCT_FD_NO LIKE 'CA%' OR ACCT_FD_NO LIKE 'SB%' GROUP BY CUST_NO HAVING COUNT(ACCT_FD_NO)>1;


Download ppt "GROUPING DATA FROM TABLE"

Similar presentations


Ads by Google