Clauses ======= 1) Group by clause ------------------- => the group by clause can be used in a select statement => can be used to group the rows of the tables into a set of summary rows by values of columns or expressions. => it can return one row per group. => group by clause must be use with aggregate functions or multi row functions like: avg(), sum(), max(), min(), count() etc. here: the aggregate functions can return summary info per group. Syntax: ------- 1) simple syntax: ------------------ select column-list from table-name group by c1, c2, c3, c4,...; Note: ------ In the simple syntax of the group by clause, the group by must be define after the "from" clause only. 2) group by clause with condition: ----------------------------------- select column-list from table-name where condition group by col1, col2, col3,...; Note: ----- here, the group by clause must be define after the where clause only. Q-1: ----- Write a SQL query to find out no.of employees are working under each department of employee table. Query: ------ select departmentNo, count(*) from employees_ashokit group by departmentNo; Q-2: Write a SQL query to find number of employees under each department who is getting more than 1000 salary based on order by departmentNo. 2) Order by clause =================== => when we want to arrange the list of information in ascending order or descending order we can use "order by clause". Syntax: select column-list from table-name group by column-name order by column-name asc/desc; here: asc ==> ascending desc ==> descending Note: ---- 1) the order by clause when we are defining with group by in the select statement, we must be define order by after the group by clause only. 2) if the order by clause is defining without group by clause in the select statement, then we allowed to define the order by clause after the from clause. Syntax: ------- for order by clause without group by clause: select column-name from table-name order by column-name asc/desc; Ex: select departmentNo from employees_ashokit order by departmentNo asc; 3) Having clause ================ => it is an optional clause of the select statement. => it can be used to filter groups of rows returned by group by clause. => having clause is usually used/defined with the group by clause only. Syntax: ------ select column-list from table-name group by col1, col2, ... having group-condition; Note: ----- having clause always define immediate to the group by clause. Q-1: Write a SQL query to find out number of employees working under each department on order of department number if a department contains at least 10 employees. select departmentNo, count(*) as emp_cnt from employees_ashokit group by departmentNo having emp_cnt >= 10; Assignment: ----------- 1) Write a SQL query to find the maximum salary of an employee under each department based on the department number from employee table. 2) Write a SQL query to find the number of employees working under each department based on job by using employee table.