Solved

MS Access - Altering query to make totals by category

Posted on 2014-01-03
3
184 Views
Last Modified: 2014-01-03
The code below produces a summary of enrollment by school for a given year.  I would like to alter this query so that I have totals by school type as opposed to individual schools.

For example, instead of listing the total for each elementary school, I want one total for school type 1, school type 2 and school type 3.  Thanks for your insight in advance.

SELECT enrollment.er_school_id, Sum(IIf([Year]=forms!select_dates!current_year,[enroll_data],0)) AS [Current Enrollment], Sum(IIf([Year]=forms!select_dates!proposed_year,[enroll_data],0)) AS [Proposed Enrollment], ([Proposed Enrollment]-[Current Enrollment]) AS [+/- Enrollment], schools.schoollName, schools.school_id, schools.Type
FROM schools INNER JOIN enrollment ON schools.school_id = enrollment.er_school_id
WHERE (((schools.open_date)<="forms]![select_dates]![current_year]") AND ((schools.close_date)>=[forms]![select_dates]![proposed_year]))
GROUP BY enrollment.er_school_id, schools.schoollName, schools.school_id, schools.Type;

Open in new window

0
Comment
Question by:Sbovino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39753745
SELECT enrollment.er_school_id, Sum(IIf([Year]=forms!select_dates!current_year,[enroll_data],0)) AS [Current Enrollment], Sum(IIf([Year]=forms!select_dates!proposed_year,[enroll_data],0)) AS [Proposed Enrollment], ([Proposed Enrollment]-[Current Enrollment]) AS [+/- Enrollment], schools.schoollName, schools.school_id, schools.Type
FROM schools INNER JOIN enrollment ON schools.school_id = enrollment.er_school_id
WHERE (((schools.open_date)<="forms]![select_dates]![current_year]") AND ((schools.close_date)>=[forms]![select_dates]![proposed_year]))
GROUP BY schools.Type;
0
 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39753773
Are your [Schools].[Open_Date] and [Schools].[Close_Date] fields actually dates?  If so, your Where clause seems flawed, as well as the fact that there should be no quotes in your where clause

SELECT Schools.Type
, Sum(IIf([Year]=forms!select_dates!current_year,[enroll_data],0)) AS [Current Enrollment]
, Sum(IIf([Year]=forms!select_dates!proposed_year,[enroll_data],0)) AS [Proposed Enrollment]
, ([Proposed Enrollment]-[Current Enrollment]) AS [+/- Enrollment]
FROM schools
INNER JOIN enrollment
ON schools.school_id = enrollment.er_school_id
WHERE (((schools.open_date)<=[forms]![select_dates]![current_year])
AND ((schools.close_date)>=[forms]![select_dates]![proposed_year]))
GROUP BY  schools.Type
0
 

Author Closing Comment

by:Sbovino
ID: 39753918
Worked perfectly.  Thank you for the comments -  they were very helpful.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question