Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping Problem

Status
Not open for further replies.

Krilyn

Programmer
Joined
Oct 29, 2003
Messages
1
Location
US
I have a SQL statement thats basically the following

select * from table group by A Having A = "Something"

Problem is I need to display all records for B that are under 7

select Count(A) as Count from table group by A,B Having A= &quot;Something&quot; and B <= 7

But if I do it this way it will group all records by B.

Count = 1 / A = Something / B = 1
Count = 1 / A = Something / B = 2
Count = 1 / A = Something / B = 3

I need to have it where it groups everything together in one record.

Count = 3 / A = Something

If anyone could help me with a way to do this it would be greatly appreciated. Thanks
 
Do you mean this:

Code:
SELECT a, COUNT(*)
FROM tbl
WHERE a = <something>
  AND b <= 7
GROUP BY a

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top