Answers to Assignment #4

Answers to Assignment #4

<p>download instant at www.easysemester.com Assignment #2 String and Aggregate Functions</p><p>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).</p><p>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</p><p>2. Create a list of courses, sections and their capacity. Produce the result in the following format: (78 rows)</p><p>Course and Section CAPACITY ------350 Section 3 ------25 10 Section 2 ------15 20 Section 2 ------15 …</p><p>SELECT LPAD(course_no||' Section '||section_no, 20) "Course and Section", RPAD('-',10,'-') " ",LTRIM(capacity) Capacity FROM section</p><p>3. Count the number of students with a “v” in their last name. Use INSTR to produce the answer. (16)</p><p>SELECT COUNT(*) "Count of V’s" FROM student WHERE INSTR(LOWER(last_name),'v') > 0</p><p>4. Show the average cost of a course with no prerequisites (1195)</p><p>SELECT AVG(cost) "Average Cost" FROM course WHERE prerequisite IS NULL</p><p>5. Display the course number, number of sections and total capacity for courses having more than 3 sections.( 9 rows).</p><p>SELECT course_no Course, COUNT(section_no) "Section Count", SUM(capacity) Capacity FROM section GROUP BY course_no HAVING COUNT(section_no) > 3</p><p>6. List all instructors and how many sections they teach. (8 rows).</p><p>SELECT instructor_id ID, COUNT(*) FROM section GROUP BY Instructor_id</p><p> download instant at www.easysemester.com download instant at www.easysemester.com 7. Do #6 but limit it to instructors teaching more than 9 sections. (6 rows).</p><p>SELECT instructor_id ID, COUNT(*) FROM section GROUP BY Instructor_id HAVING COUNT(*) > 9</p><p> download instant at www.easysemester.com</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us