poe Posted November 15, 2006 Share Posted November 15, 2006 team opp wlt gf ga-----------------------------------------tor mtl w 5 1 tor phi w 4 1 tor atl w 4 2 tor ott l 2 6 tor nyr so 4 5 tor col l 1 4 tor cgy w 5 4 tor fla w 2 1 tor mtl so 2 3 tor ott l 1 4 the result i want is:team games wins loss tie ttlgf ttlga - ...note (so=tie) tor 10 5 3 2 30 31the query i have is :query = SELECT team, count(team), count(wlt), sum(gf), sum(ga) FROM games WHERE team='tor'basically:get the teamgames = count the rowswins = count 'w'loss = count 'l'tie = count 'so'ttlgf & ttlga = sum()thanks Link to comment https://forums.phpfreaks.com/topic/27313-combining-sum-and-counts-in-1-query/ Share on other sites More sharing options...
shoz Posted November 15, 2006 Share Posted November 15, 2006 [code]SELECTteam, COUNT(*) AS games,SUM(wlt = 'w') AS wins, SUM(wlt = 'l') AS loss, SUM(wlt = 'so') AS tie,SUM(gf) AS ttlgf, SUM(ga) AS ttlgaFROMgamesWHEREteam = 'tor'[/code] Link to comment https://forums.phpfreaks.com/topic/27313-combining-sum-and-counts-in-1-query/#findComment-124994 Share on other sites More sharing options...
fenway Posted November 15, 2006 Share Posted November 15, 2006 Interesting... I thought you had to use the SUMIF() function for that. Link to comment https://forums.phpfreaks.com/topic/27313-combining-sum-and-counts-in-1-query/#findComment-125119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.