Anda di halaman 1dari 1

Assignment #3

Date and Conversion Functions Answers


1. Determine the Start Time for all sections of course 20. The time should be displayed as Month,
Date, Year, Hour, and Minute, with a column alias of Start Time (4 rows).
SELECT TO_CHAR(start_date_time,'MM/DD/YYYY HH:MI')
"Start Time",section_no
FROM section
WHERE course_no = 20
2. Determine the difference in days between the first start time of a class and the last start time
for a course when the course has more than one section (18 rows).
SELECT MAX(start_date_time) - MIN(start_date_time),
course_no, COUNT(course_no)
FROM section
GROUP BY course_no
HAVING COUNT(course_no) >1
3. Display the start time of section 140 with the following format:
Start Time
-------------------------------MONDAY, 16th APRIL, 1999 9:30 AM
SELECT TO_CHAR(start_date_time,
'fmDAY ddth MONTH,YYY HH:MI AM') "Start Time"
FROM section
WHERE section_id = 140
4. Write a SELECT statement to determine how many students enrolled in February 2007 (157
rows).
SELECT
FROM
WHERE
AND

COUNT(DISTINCT student_id)
enrollment e
enroll_date >=TO_DATE('01-FEB-2007')
enroll_date <TO_DATE('01-MAR-2007')

5. Show a list of course numbers, their description and their prerequisites. If the prerequisite is
null, substitute None using NVL and a data conversion function.
SELECT course_no, NVL(TO_CHAR(prerequisite) ,'None')
FROM course
6. Using DECODE, write a query that checks the phone number of students. If the area code is
212, remove it. If it is anything else., put a 1- in front of the phone number. Display the student
name and the phone number. If they have no phone number, display No Phone.
SELECT first_name||' '||last_name Student,
DECODE(SUBSTR(phone,1,3),'212',
SUBSTR(phone,5),
null, 'No phone',
'1-'||phone) Phone
FROM student

Anda mungkin juga menyukai