Solved

Find count within a query

Posted on 2014-04-04
4
255 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
  • 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 40

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how the fundamental information of how to create a table.

830 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