Jump to content
  • Advertisement
Sign in to follow this  
mike74

sql

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way to SELECT the total number of rows being dealt with when you do a GROUP BY? If you SELECT COUNT(*) it won't return the total if your rows are being grouped. I'm trying to produce stats like the following for a football squares game: Square #'s % 7,4 3.8 4,7 3.8 7,0 3.7 0,7 3.7 0,3 3.3 3,0 3.3 4,1 2.3 The table I'm accessing looks like this: CREATE TABLE `prizemoney` ( `gameid` int(11) NOT NULL default '0', `username` varchar(40) NOT NULL default '', `moneywon` float NOT NULL default '0', `quarterwon` tinyint(4) NOT NULL default '0', `rownum` tinyint(4) NOT NULL default '0', `colnum` tinyint(4) NOT NULL default '0', `rowvalue` tinyint(4) NOT NULL default '0', `colvalue` tinyint(4) NOT NULL default '0' ) TYPE=MyISAM COMMENT='Contains info on who won what'; I'd like to take care of the entire stats with a single SQL statement. Mike http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Advertisement
try:

SELECT Count(*)
FROM (SELECT gameid, username, Count(*) count
FROM prizemoney
GROUP BY gameid, username) a

or try

SELECT Count(*)
FROM (SELECT DISTINCT gameid, username
FROM prizemoney
GROUP BY gameid, username) a

or

SELECT Count(DISTINCT username)
FROM prizemoney

This is examples how to get number of rows when you do a GROUP BY

Share this post


Link to post
Share on other sites
The first two queries don't work. The last query works but seem entirely unrelated to what I'm trying to do.

Mike
http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
I'm rusty.

Assuming you want to find the number of final, grouped rows, first try:

select count(one of the grouping rows)

and if that doesn't work, you have to use a subquery.

If you're trying to figure out how many rows are inside each group, just select count(column_c) where column_c is one that's NOT part of the group-by clause.


What SQL flavor are you using? MySQL? SQL Server 2000? Oracle?

Share this post


Link to post
Share on other sites
I'm trying to figure out how many rows there would be with no grouping. I'm using MySQL.

Mike
http://www.coolgroups.com/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!