2-Expriment 2数据库实验

  • 格式:doc
  • 大小:31.00 KB
  • 文档页数:2

Experiment 2. Expressions and GROUP BY clause
1. Search conditions
1.1 Select rows within a certain range. (Using BETWEEN…AND…)
a. Find all the employees who earn between $1200 and $1400.
b. Find all the employees who do not earn between $1200 and $1400.
1.2 Select rows that match a value in a list. (Using IN(…) operator)
a. Find the employees who are clerks, analysts or salesmen.
b. Find the employees who are not clerks, analysts or salesmen.
1.3 Select rows that match a character string pattern. (Using LIKE operator)
a. Find all the employees whose names begin with the letter “M”.
b. Find all the employees whose names contain the letter “N”.
c. Find all the employees whose names are not 5 characters long.
2. Ordering rows in a query result
2.1 List the employees in department 30 ordered by their salaries in ascending order.
2.2 List the employees in department 30 ordered by their salaries in descending order.
2.3 Order all employees by job. For those with the same job, put them in descending salary order.
3. Expressions
3.1 The ISNULL() function.
Syntax: ISNULL ( check_expression , replacement_value )
Description: Check whether check_expression is a null value. If it is, replace it with replacement_value in the expression.
Example: Calculate the average price of all books. Consider the books without price data as $20.
SELECT AVG(ISNULL(Price, 20)) FROM Books;
3.2 List the name, salary, commission, and sum of salary plus commission of all salesmen.
3.3 List the name, salary and commission of employees whose commissions are greater than 25% of their salaries.
3.4 Calculate the total annual earnings of all salesmen based on their monthly salaries and their monthly commissions.
4. Aggregate Functions
4.1 Find the average salary for clerks.
4.2 Find the total salary and total commission for salesmen.
4.3 Compute the average annual salary plus commission for all salesmen.
4.4 Find the highest and lowest paid employee salaries and the difference between them.
4.5 Count the number of employees who receive a commission.
4.6 Count the number of different jobs held by employees in department 30.
4.7 Count the number of employees in department 30.
5. GROUP BY clause
5.1 List the department number and average salary of each department.
5.2 F ind each department’s average annual salary for all its employees except the managers and the president.
5.3 Divide all employees into groups by department, and by jobs within department. Count the employees in each group and compute each group’s average annual salary.
5.4 List the average annual salary for all job groups having more than 2 employees in the group.
5.5 List all the departments that have at least two clerks.
5.6 Find all departments with an average commission greater than 25% of average salary.。