SQL Assignment
SQL Assignment
SQL Assignment
true
false
3. There are four coding errors in the following statement. Can you identify them?
There is no operator x;
4. If you concatenate a NULL value with a character string, the result is NULL. (TRUE/FALSE)
false
5. Write a query to display all columns and all rows from employees table.
6. Which arithmetic operations are valid for DATE and TIMESTAMP data?
Date+number,date-number,date-date,date+number/24
7. Write a query to display employee number, employee name and to calculate a salary increase of
employees;
8. What is the default rule of precedence in arithmetic expression?
*,/,+,-
9. Write down the syntax to display the structure of the DEPARTMENTS table.
Desc departments;
10. Write a query to display the last name, job code, hire date, and employee number for each
employee, with the employee number appearing first. Provide an alias STARTDATE for the
HIRE_DATE column.
11. Write a query to display all unique job codes from the EMPLOYEES table.
12. The HR department has requested a report of all employees and their job IDs. Display the last
name concatenated with the job ID (separated by a comma and space) and name the column
13. Write a query to display all the data from employees table. Separate each column output with a
SELECT EMPLOYEE_ID||’,’||FIRST_NAME||’,’||LAST_NAME||’,’||EMAIL||’,’||PHONE_NUMBER||’,’||
HIRE_DATE||’,’||JOB_ID||’,’||SALARY||’,’||COMMISSION_PCT||’,’||MANAGER_ID||’,’||
DEPARTMENT_ID
14. Write a query to display the last name and salary of employees who earn more than $12,000.
15. Write a query to display the last name and department number for employee number 176.
are Matos or Taylor. Order the query in ascending order by hire date.
by hire_date;
17. Write a query to display the last name and department number of all employees in departments
Order by last_name;
last_name;
18. Values that are specified with the BETWEEN condition are exclusive. (TRUE/FALSE).
True;
false
19. Write a query to display the last name and salary of employees who earn between $5,000 and
$12,000, and are in department 20 or 50. Label the columns Employee and Monthly Salary,
respectively.
False;
21. Write a query to display the last name and hire date for all employees who were hired in 1994.
22. Write a query to display the last name and first name of all employees who do not have a
manager.
LAST_NAME FIRST_NAME
------------------------- --------------------
King Steven
False.
24. While using BETWEEN operators, either lower limit or upper limit can be used first. (TRUE/FALSE)
false
25. Write a query to display employee numbers, last names, and salaries for all the employees
False
true
27. Write a query to display the last name, salary, and commission of all employees whose
commission has been decided. Sort the data in descending order of salary and commissions.
Select last_name,salary commission_pct from employees where commission_pct is not null order
by salary desc,commission_pct ;
28. Which symbols are used for wildcard searching with LIKE operator? Describe about those.
% and _ are used as wildcard characters. Both are used in like operator where exact value is not
known to search where _ represents any single character and % represents any sequence of
% and _ are used as wildcard characters. Both are used in like operator where exact value is not
known to search where _ represents any single character and % represents any number of
characters;
29. Write a query to display employee number, last name and salary of all employees, who are
working in department number 40 or their name first name contains an ‘e’ as third letter.
like(‘__e%’);
30. What is the use of BETWEEN operator, IN operator and LIKE operator in Oracle?
LIKE operator- It’s used exact values are not known to search;
LIKE operator- It’s used to search when exact values are not known
31. Write a query to display the lastname and salary of all employee in which the third letter of the
firstname is “a.”
SA_.
Escape(‘\’);
33. Write a query to display the last names of all employees who have both an a and an e in their
last name.
%');
34. Write a query to display the last name, job, and salary for all employees whose jobs are either
that of a sales representative or a stock clerk, and whose salaries are not equal to $2,500,
$3,500, or $7,000.
Select last_name,job_id,salary from employees where (job_id=’ ST_CLERK’’ And salary not in
35. Write a query to display the current date. Label the column as Date.
36. Write a query to display the employee number, last name, salary, and salary increased by 15.5%
(expressed as a whole number) for each employee. Label the column “New Salary”.
employees;
37. Single-row functions can not modify the data type (TRUE/FALSE).
false
38. Write down three examples of GENERAL FUNCTIONS available in Oracle SQL.
NVL,NVL2,NULL IF
nullif
false
40. Write a query that displays the last name (with the first letter uppercase and all other letters
lowercase) and the length of the last name for all employees whose name starts with the letters
41. Write a query to display the last name and calculate the number of months between today and
the date on which the employee was hired. Label the column MONTHS_WORKED. Order your
results by the number of months employed. Round the number of months up to the closest whole
number.
<employee last name> earns <salary> monthly but wants <3 times salary>. Label the
from employees;
43. Write a query to display the last name and salary for all employees. Format the salary to be 15
characters long, left-padded with the $ symbol. Label the column SALARY.
44. Which SQL function is used to return the last day of a month?
Last_day
45. Write a query to display each employee’s last name, hire date, and salary review date, which is
the first Monday after six months of service. Label the column REVIEW.
46. SYSDATE is a SQL function which returns current date, time and time zone information
(TRUE/FALSE).
false
47. Write a query to display the last name, hire date, and day of the week on which an employee
started. Label the column DAY. Order the results by the day of the week.
does not earn a commission, show “No Commission.” Label the column COMM.
49. The ROUND and TRUNCATE function can be used for NUMBER and DATE values. (TRUE/FALSE)
true
true
51. Using the CASE function, write a query that displays the grade of all employees based on the
Job Grade
AD_PRES A
ST_MAN B
IT_PROG C
SA_REP D
ST_CLERK E
52. Group functions work across many rows to produce one result per group (TRUE/FALSE).
true
53. The WHERE clause restricts rows before inclusion in a group calculation (TRUE/FALSE).
False
true
54. MIN and MAX functions can be applied against numeric, character and date data type
(TRUE/FALSE).
true
Any coloumn name which is used before group fns that must be included in GROUP BY clause .
56. Write a query to find the highest, lowest, sum, and average salary of all employees. Label the
columns Maximum, Minimum, Sum, and Average, respectively. Round your results to the nearest
whole number.
select job_id,max(salary) as "MAXIMUM",min(salary) as "MINIMUM",sum(salary) as
57. All columns in the SELECT list that are not in GROUP functions must be in the GROUP BY clause
(TRUE/FALSE).
True;
58. Write a Query to display the minimum, maximum, sum, and average salary for each job type.
59. SELECT department_id, AVG(salary) FROM employees WHERE AVG(salary) > 8000 GROUP BY
department_id;
60. Write a query to display the number of people with the same job.
61. You can use a column alias in the GROUP BY clause (TRUE/FALSE).
False.
62. Write a query to determine the number of managers without listing them. Label the column
Number of Managers.
Number of Managers
------------------
18
63. Write a query to find the difference between the highest and the lowest salaries. Label the
column DIFFERENCE.
----------
21900