kateland Posted January 6, 2007 Share Posted January 6, 2007 GAME_USERINV (stores a user's inventory of games they own)gid (game id)user_idGAME_INV (master list of all games loaded)gid (game id)game_titleI'm trying to write a SQL statement that will plunk out the game that appears in the most users' inventories. The COUNT() function seems to be only to count items in a group...not the frequency. Pardon the funky code, this is phpbb not pure php.I'm guessing an INNER JOIN is useful since it will ignore all the other games that DON'T exist in someone's inventory. yes??[code]$sql = "SELECT gu.*, gi.gid, gi.game_title, COUNT(gu.gid) AS count_freqFROM " . GAME_USERINV . " AS guINNER JOIN " . GAME_INV_TABLE . " AS gi ON gu.gid = gi.gidGROUP BY gi.game_title";[/code]Yeah, this totally does not work. Help! :) Link to comment https://forums.phpfreaks.com/topic/33039-counting-frequencies/ Share on other sites More sharing options...
Eugene Posted January 6, 2007 Share Posted January 6, 2007 $sql = "SELECT gu.*, gi.gid, gi.game_title, COUNT(DISTINCT gu.gid) AS count_freqFROM " . GAME_USERINV . " AS guINNER JOIN " . GAME_INV_TABLE . " AS gi ON gu.gid = gi.gidGROUP BY gi.game_title";I hope that helps. Link to comment https://forums.phpfreaks.com/topic/33039-counting-frequencies/#findComment-153924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.