10 Lab Practice 2 Q1 Q10
10 Lab Practice 2 Q1 Q10
Use the Sales database which you had created in the previous week for this exercise.
Answer:
Answer:
SELECT *
FROM Customer;
3. List the IDs and names of all salespersons. Rename these columns to ‘Salesperson _ID’
and ‘Salesperson_Name’ respectively.
Answer:
3a) List the IDs, names and cities for all customers. Label these columns as
‘Customer Number’, ‘Name’ and ‘City’ respectively.
4. List the names of all cities which all customers live in.
Answer:
_________________________________________________________________________
Page 1 of 4
CT042-3-1-IDB Lab Practice 2
5. List the name, monthly and annual salaries for all salespersons. Label these columns as
EmpName, Monthly Salary and Annual Salary respectively.
Answer:
5a) List the name, monthly and quarterly salaries for all salespersons. Label these
columns as EmpName, Monthly Salary and Quarterly Salary.
6. List the IDs and names of all salespersons with a salary greater than 2000.
Answer:
6a) List the IDs and names of all customers from ‘Kuala Lumpur’.
6b) List the IDs and names of all employees with rank level 2.
Answer:
-- Use IN as an alternative.
7a) List the IDs and names of all salespersons with rank levels ‘1’ and ‘2’.
_________________________________________________________________________
Page 2 of 4
CT042-3-1-IDB Lab Practice 2
8. List the names and rank levels of all salespersons with a salary between 1500 and 2000.
Answer:
8a) List the IDs and names of all salespersons with rank levels between ‘1’ and ‘3’.
9. List the names of customers with credit ratings other than ‘B’ and ‘C’.
Answer:
SELECT *
FROM Customer
WHERE CreditRating NOT IN ('B', 'C');
-- Alternative answer
SELECT *
FROM Customer
WHERE (CreditRating != 'B') AND (CreditRating < > 'C');
9a) List the IDs and names of all customers who are not from ‘Ipoh’ or ‘Georgetown’.
1. List the names of all customers whose names contain the letters ‘rk’.
Answer:
SELECT CustName
FROM Customer
WHERE CustName LIKE '%rk%';
_________________________________________________________________________
Page 3 of 4
CT042-3-1-IDB Lab Practice 2
10a) List the names and IDs of all salespersons whose names contain the string ‘ri’.
10b) List the names and IDs of all salespersons whose names start with the letter ‘B’
10c) List the names and IDs of all salespersons whose names end with the letter ‘s’.
_________________________________________________________________________
Page 4 of 4