This document outlines 7 assignments involving string and aggregate functions in SQL. The assignments include: 1) Removing middle initials from student names, 2) Listing course sections and capacities, 3) Counting students with "v" in their last name, 4) Calculating average cost of courses with no prerequisites, 5) Displaying courses with over 3 sections and their total capacity, 6) Listing instructors and number of sections taught, 7) Listing instructors teaching over 9 sections.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
219 views2 pages
Assign2 Ans
This document outlines 7 assignments involving string and aggregate functions in SQL. The assignments include: 1) Removing middle initials from student names, 2) Listing course sections and capacities, 3) Counting students with "v" in their last name, 4) Calculating average cost of courses with no prerequisites, 5) Displaying courses with over 3 sections and their total capacity, 6) Listing instructors and number of sections taught, 7) Listing instructors teaching over 9 sections.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2
Assignment #2
String and Aggregate Functions
1. Create a list of all students with middle initials (specifically, with a first name AND then a middle initial) AND remove the middle initial from the first name. Take care: some first names are a single initial only. [HINT: use the INSTR function embedded within other functions). (7 rows). SELECT first_name Name, SUBSTR(first_name,1,INSTR(first_name,' ') - 1) "Instr Name" FROM student WHERE INSTR(first_name,' ') < INSTR(first_name,'.') AND INSTR(first_name,' ') <> 0 AND INSTR(first_name,'.') <> 0 2. Create a list of courses, sections and their capacity. Produce the result in the following format: (78 rows) Course and Section -------------------350 Section 3 10 Section 2 20 Section 2
"Course and Section", RPAD('-',10,'-') " ",LTRIM(capacity) Capacity FROM section 3. Count the number of students with a v in their last name. Use INSTR to produce the answer. (16) SELECT COUNT(*) "Count of Vs" FROM student WHERE INSTR(LOWER(last_name),'v') > 0 4. Show the average cost of a course with no prerequisites (1195) SELECT AVG(cost) "Average Cost" FROM course WHERE prerequisite IS NULL 5. Display the course number, number of sections and total capacity for courses having more than 3 sections.( 9 rows). SELECT course_no Course, COUNT(section_no) "Section Count", SUM(capacity) Capacity FROM section GROUP BY course_no HAVING COUNT(section_no) > 3 6. List all instructors and how many sections they teach. (8 rows). SELECT instructor_id ID, COUNT(*) FROM section GROUP BY Instructor_id 7. Do #6 but limit it to instructors teaching more than 9 sections. (6 rows). SELECT FROM GROUP HAVING