You are on page 1of 2

# www.oracle.

Database Foundations
6-8 : Sorting Data Using ORDER BY
Practice Solutions
Exercise 1: Sorting Data Using ORDER BY

Overview
In this practice you will:
• Sort rows by using the ORDER BY clause

1. Display all fields for each of the records in ascending order for the following tables:

Solution:
SELECT ID, FIRST_NAME, LAST_NAME,PARENT_ID, REG_YEAR, EMAIL
ORDER BY REG_YEAR;

## b. AD_EXAM_RESULTS ordered by STUDENT_ID and COURSE_ID

Solution:
ORDER BY COURSE_ID, STUDENT_ID;

## c. AD_STUDENT_ATTENDANCE ordered by STUDENT_ID

Solution:
SELECT STUDENT_ID, NUM_WORK_DAYS,NUM_DAYS_OFF,EXAM_ELIGIBILITY
ORDER BY STUDENT_ID;

## d. AD_DEPARTMENTS ordered by DEPT_ID

Solution:
ORDER BY ID;

2

2. Display the percentage of days students have taken days off and sort the records based on the percentage calculated.

Solution:
SELECT STUDENT_ID, ((NUM_DAYS_OFF/NUM_WORK_DAYS)* 100) AS PERCT, EXAM_ELIGIBILITY
ORDER BY PERCT;

## 3. Display the top 5 students based on exam grade results.

Solution:
SELECT ROWNUM As "HIGH SCORES",STUDENT_ID, EXAM_ID, EXAM_GRADE
FROM