![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
But I just can't make it work to squeeze that into the other query as a subquery. All help appreciated. Mike |
#3
| |||
| |||
|
|
On 2010-10-22 20:30, MikeB wrote: [...] But I just can't make it work to squeeze that into the other query as a subquery. All help appreciated. Mike Can you post the table definition (as a create statement) and some sample data as insert statements? Hope this is enough data, I don't want to flood a lot of stuff onto |
#4
| |||
| |||
|
|
Lennart Jonsson wrote: On 2010-10-22 20:30, MikeB wrote: [...] But I just can't make it work to squeeze that into the other query as a subquery. All help appreciated. Mike Can you post the table definition (as a create statement) and some sample data as insert statements? Hope this is enough data, I don't want to flood a lot of stuff onto here. I can post more data if needed. CREATE TABLE IF NOT EXISTS `scoresUncharted` ( `ts` timestamp NOT NULL default CURRENT_TIMESTAMP, `map` varchar(32) NOT NULL, `user` varchar(15) NOT NULL, `group` varchar(20) NOT NULL, `score` mediumint(8) unsigned NOT NULL, `playCount` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`map`,`user`), KEY `ts` (`ts`), KEY `map` (`map`), KEY `user` (`user`), KEY `group` (`group`), KEY `score` (`score`), KEY `playCount` (`playCount`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; |
|
xgroup | players | +-------------+---------+ Marauders | 4 | Resubmitted | 1 | +-------------+---------+ |
|
xgroup | players | +-------------+---------+ Resubmitted | 1 | Marauders | 1 | +-------------+---------+ |
#5
| |||
| |||
|
|
PRIMARY KEY (`map`,`user`), KEY `ts` (`ts`), KEY `map` (`map`), |
#6
| |||
| |||
|
|
On 2010-10-23 14:48, MikeB wrote: Lennart Jonsson wrote: On 2010-10-22 20:30, MikeB wrote: [...] But I just can't make it work to squeeze that into the other query as a subquery. All help appreciated. Mike Can you post the table definition (as a create statement) and some sample data as insert statements? Hope this is enough data, I don't want to flood a lot of stuff onto here. I can post more data if needed. CREATE TABLE IF NOT EXISTS `scoresUncharted` ( `ts` timestamp NOT NULL default CURRENT_TIMESTAMP, `map` varchar(32) NOT NULL, `user` varchar(15) NOT NULL, `group` varchar(20) NOT NULL, `score` mediumint(8) unsigned NOT NULL, `playCount` mediumint(8) unsigned NOT NULL, PRIMARY KEY (`map`,`user`), KEY `ts` (`ts`), KEY `map` (`map`), KEY `user` (`user`), KEY `group` (`group`), KEY `score` (`score`), KEY `playCount` (`playCount`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Given your data (I replace a number of reserved words in the table) we have: SELECT x.xgroup, COUNT(x.xuser) AS players FROM scoresUncharted x GROUP BY x.xgroup HAVING (x.xgroup<> '') ORDER BY players DESC; +-------------+---------+ | xgroup | players | +-------------+---------+ | Marauders | 4 | | Resubmitted | 1 | +-------------+---------+ 2 rows in set (0.05 sec) If you want the distinct number of players in each group you can: SELECT x.xgroup, COUNT(distinct x.xuser) AS players FROM scoresUncharted x GROUP BY x.xgroup HAVING (x.xgroup<> '') ORDER BY players DESC; +-------------+---------+ | xgroup | players | +-------------+---------+ | Resubmitted | 1 | | Marauders | 1 | +-------------+---------+ 2 rows in set (0.00 sec) Is this what you want? |
#7
| |||
| |||
|
|
In article<4cc2d98a (AT) news (DOT) x-privat.org>, MikeB<mpbrede (AT) gmail (DOT) com> wrote: [...] PRIMARY KEY (`map`,`user`), KEY `ts` (`ts`), KEY `map` (`map`), Just FYI, since 'map' is already the high-order portion of the primary key, having a separate index on that column alone is completely unnecessary. |
![]() |
| Thread Tools | |
| Display Modes | |
| |