Chapter 7 Querying Using SQL
Chapter 7 Querying Using SQL
Q- Write a query to find the average salary of employee for job of salesman.
2. COUNT – This function is used to counts the number of values in a column or
expression. While counting it ignore the NULL values.
Count(*) – Returns the number of rows satisfying the condition, if any in
the table.
Count (Column Name) – Return Non-NULL values in the column.
Example 1 – Count number of records in table emp.
Example 2 – Count Number of jobs in table empl i.e. count values in job column.
3. MAX – This function returns the maximum value from a given column or
expression.
Example 1 – Display maximum salary from table empl.
Aggregate functions and NULL values: All aggregate functions ignore NULL values.
The * is the only argument that includes NULLs when it is used with COUNT function.
Example 1 – Following query output indicate that there are 5 records in the table empl.
Example 2 –
Output indicates that there are 3 values in the comm Column of empl table.
This feature of aggregate functions ensures that NULLs don’t play any role in
actual calculations. For example
The average comm has been calculated for all the 3 non-NULL values.
Specifying Custom Sort Order : We can also arrange data as per our own specified
order. We can do this by using the FIELD function in ORDER BY clause.
Example 4 : We can use an aggregate function in the HAVING even if it is not in the
SELECT list.
Query - Find the department-wise total salary where number of employees is more
than 2.
Solved Problems :
1 – 5, 9, 11, 13,15, 17 – 19
Assignment
Type – A
Q1, 10,
Type – B
Q10 , 11