You are on page 1of 3

There are four coding errors in this statement. Can you identify them?

SELECT
employee_id, last_name sal x 12 ANNUAL SALARY
FROM employees;
1) There is no comma(,) after last_name.
2) There is no 'x' operator. Instead it's *for multiplication.
3) There is no column named "sal" in the given table images.
4) Since the intention of multiplying sal by 12 and storing it in an alias name, the alias
name should not include spaces.

Create a query to display the last name, job code, hiredate, and employee number
for each employee, with employee number appearing first.
SELECT Emp#, employee, JOBB, HIREDATE FROM sdemp;

Display the last name concatenated with the job ID, separated by a comma and
space, and name the column Employee and Title.
SELECT employee||', '||jobb "Employee and Title" FROM sdemp;

Create a query to display all the data from the EMPLOYEES table. Separate each
column by a comma. Name the column THE_OUTPUT.
SELECT employee||','||jobb||','||emp#||','||hiredate||','||salary "THE_OUTPUT" FROM
sdemp;

Create a query to display the last name and salary of employees earning more than
$12,000.
Salary coloumn is not present. It's assumed to be as 'salary'.
SELECT employee,salary FROM sdemp WHERE salary>12000;

Create a query to display the employee last name and department number for
employee number 176.
select employee,depnum from sdemp where emp# =176;

Display the last name and salary for all employees whose salary is not in the range
of $5,000 and $12,000.
select employee,salary from sdemp where salary not between 5000 and 12000;
Display the employee last name, job ID, and start date of employees hired between
February 20, 1998, and May 1, 1998
select employee, jobb, hiredate from sdemp where hiredate between '20-FEB-1998' and
'01-MAY-1998';

Display the last name of all employees who have an 'a' and an 'e' in their last name.
select employee from sdemp where employee like '%a%' and employee like'%e%';

Display the last name, job, and salary for all employees whose job is sales
representative or stock clerk and whose salary is not equal to $2,500, $3,500, or
$7,000.
Note : Sales Representative is considered as SALES_REP
select employee,jobb,salary from sdemp where jobb in('SALES_REP', 'ST_CLERK') and
salary not in (2500,3500,7000);

Change the last name of employee 3 to Drexler.


update sdemp
set employee='Drexler'
where emp#=3;

Change the salary to 10000 for all employees with a salary less than 9000.
Note: Salary coloumn is assumed as salary.
update sdemp
set salary=10000
where salary<9000

Delete employees whose salary is betweeen 39000 and 41000.


delete from sdemp
where salary between 39000 and 41000;
Get all the employees whose employee name contains in in them.
select employee from sdemp where employee like '%in%';

Display all the columns from employee table along with a column which calculates
10 times the salary of each employee.
select employee,salary,salary * 10 AS new_salary from sdemp;
Create a new table as employee table and empty the newly created table.
create table employee;
delete from employee;

Make sure the newly created table has no records.


select *from employee; now verify the table is empty.

Using employee table sort the table with the employee name.
select *from sdemp order by employee

NOTE : THE ABOVE QUERIES ARE JUST WRITTEN LOGIC. THEY'VE NOT
BEEN EXECUTED CAUSE DELETING THE TABLE WOULD RESULT IN
FAILURE WHEN T ALL OTHER ABOVE QUERIES ARE EXECUTED

You might also like