Solved

Find count within a query

Posted on 2014-04-04
4
259 Views
Last Modified: 2014-04-05
I have the following sql query

SELECT Max(Text4)Text4,Max(Text5)Text5,Max(Combo11)Combo11, Sum(Total)TotalsperStudent FROM AttendanceGrid INNER JOIN tblRegistration ON AttendanceGrid.[ID]=tblRegistration.[ID] Where  AttendanceGrid.Fiscal = '2014'  Group by tblRegistration.ID HAVING Sum(Total)>0 

Open in new window


The output looks like this:

Text4	Text5	Combo11	TotalsperStudent
Guthrie	Tionne	Mid Austin	   129
Rodriguez	Eleany	LOS	52
Meeks	Quiana	Major Adams	   53
Colley	Kayla	Mid Austin	     236

Open in new window


How can I change the query to get the following output.  I want to find out how many records there are per group (Combo11)?

My desired output based on the above results would be:

Mid Austin   2
LOS                1
Major Adams  1

Open in new window

0
Comment
Question by:al4629740
[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
  • 2
4 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 39979372
SELECT Combo11, COUNT(DISTINCT Text4+Text5) Recs_Per_Group
FROM AttendanceGrid
INNER JOIN tblRegistration ON AttendanceGrid.[ID]=tblRegistration.[ID]
Where  AttendanceGrid.Fiscal = '2014'  
Group by Combo11
0
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 39979423
SELECT Combo11, 
       COUNT(*) Cnt 
  FROM (SELECT MAX(Combo11)Combo11 
          FROM AttendanceGrid 
               INNER JOIN tblRegistration 
                       ON AttendanceGrid.[ID] = tblRegistration.[ID] 
         WHERE AttendanceGrid.Fiscal = '2014' 
         GROUP BY tblRegistration.ID 
        HAVING SUM(Total) > 0) T1 
 GROUP BY Combo11 

Open in new window

0
 

Author Comment

by:al4629740
ID: 39980593
SELECT Combo11,
       COUNT(*) Cnt

What does Cnt stand for or do?
0
 

Author Comment

by:al4629740
ID: 39980603
nevermind....
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

734 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