Professional Documents
Culture Documents
a. Display all student grades, showing columns: course description, student name,
grade; to be sorted by: course (ASC) + grade (DESC)
b. Display the list of course (the description of each) with the statistics: the
minimum, maximum and average grade per course
c. Display the list of students (the name for each) and the number of courses
followed by each student
d. Display the total count of students following Java related courses (which contain
'Java' in their description)
e. Display the name and average grade for the student with the greatest average
grade (based on grades from all his followed courses)
f. Update the grades of all students following the Java related courses, by
increasing current grade by +1, but without getting them past 10
- UPDATE:
1. Write a query to update the portion of the phone_number in the employees table,
within the phone number the substring '590' will be replaced by '111'. Hint: use
REPLACE function.
2. Write a query to append '@wantsome.ro' to email field. Hint: use CONCAT
function.
3. Write a SQL statement to change salary of employee to 8000 with ID is 105, if
the existing salary is less than 5000.
4. Write a SQL statement to change job ID of employee with ID is 118 to
SH_CLERK if the employee belongs to the department with ID 30 and the
existing job ID does not start with SH.
5. Write a SQL statement to increase the salary of employees under the
departments 40, 90 and 110 according to the company rules that, salary will be
increased by a factor of 2 for the department 40, 3 for department 90 and 10 for
the department 110 and the rest of the departments will remain the same.
- SELECT:
1. Write a query to get the details of the employees where the length of the first
name greater than or equal to 8. Hint: Use LENGTH function.
2. Write a query that displays the first name and the length of the first name for all
employees whose name starts with letters 'A', 'J' or 'M'. Give each column an
appropriate label. Sort the results by the employees' first names.
3. Write a query to list the department ID and name of all the departments where no
employee is working.
4. Write a query to display the employee ID, first name, last name, salary of all
employees whose salary is above average for their departments.
5. Write a query to find the name (first_name, last_name), and salary of the
employees who earns more than the earning of Mr. Bell.
6. Write a query to display the name (first_name, last_name), salary and TAX (15%
of salary) of all employees.
- JOIN:
1. Write a query to display the job history that were done by any employee who is
currently earning more than 10000.
2. Write a query to display job name, employee name, and the difference between
the salary of the employee and minimum salary for the job.
3. Write a query to display the job name and average salary of employees.
4. Write a query to display the department name, manager name, and city.
5. Write a query to display the department ID and name and first name of manager.
6. Write a query to find the employee ID, job name, number of days between ending
date and starting date for all jobs in department 90 from job history.
-- Sample data:
insert into regions values('2','Americas');
insert into regions values('3','Asia');
insert into regions values('1','Europe');
insert into regions values('4','Middle East and Africa');
insert into regions values('7','Moldova');
a. select the unique city values that reside in the state of California and order the
results in descending order by city
b. select all records and order them in ascending order after state and city
CREATE TABLE suppliers ( supplier_id int NOT NULL, supplier_name char(50) NOT NULL,
city char(50), state char(25), CONSTRAINT suppliers_pk PRIMARY KEY (supplier_id) );
Based on the CUSTOMERS and ORDERS tables created by the scripts below:
a. select the customer_id and last_name from the customers table and select the
order_date from the orders table where there is a matching customer_id value
in both the customers and orders tables. Order the results by customer_id in
descending order
b. select the first_name and last_name of customers who initiated an order in the
last month
d. select the customer_id and last_name from the customers table where there is
a record in the orders table for that customer_id. Order the results in ascending
order by last_name and then descending order by customer_id
CREATE TABLE customers ( customer_id int NOT NULL, last_name char(50) NOT NULL, first_name
char(50) NOT NULL, favorite_website char(50), CONSTRAINT customers_pk PRIMARY KEY
(customer_id) );