Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with changing the query which does pivot of counts of sections offered by department by selected years, but the years are explicitly selected

Need help with changing the query which does pivot of counts of sections offered by department by selected years, but the years are explicitly selected for display.

Want to tweak the query so that all the years are dynamically displayed, i.e. we do not need to explicitly select years to be displayed.

select dept_name,

(select count(s2.sec_id) from section s2 join course c2 on s2.course_id = c2.course_id

where c2.dept_name = course.dept_name

and s2.year in (2002, 2003, 2004, 2007, 2009, 2010)) "Count in that dept",

(select count(sec_id) from section) "Overall Count",

sum(if(year = 2002, 1,0)) as 'Year 2002',

sum(if(year = 2003, 1,0)) as 'Year 2003',

sum(if(year = 2004, 1,0)) as 'Year 2004',

sum(if(year = 2007, 1,0)) as 'Year 2007',

sum(if(year = 2009, 1,0)) as 'Year 2009',

sum(if(year = 2010, 1,0)) as 'Year 2010'

from section join course on section.course_id = course.course_id

group by dept_name

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modernize Your Audit Department Five Critical Areas For Improvement

Authors: Toby DeRoche

1st Edition

B08FKW8B91, 979-8674160274

More Books

Students also viewed these Accounting questions

Question

What are the classifications of Bank?

Answered: 1 week ago