Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find count within a query

Posted on 2014-04-04
4
Medium Priority
?
271 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 70

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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

597 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