danbopes Posted November 3, 2008 Share Posted November 3, 2008 This is my query: SELECT hlstats_Players.lastName AS name, hlstats_Players.flag AS flag, hlstats_Players.country AS country, COUNT(hlstats_Frags_Kills.kills) AS kills, COUNT(hlstats_Frags_Kills.deaths) AS deaths, hlstats_Frags_Kills.playerId as victimId, IFNULL(COUNT(hlstats_Frags_Kills.kills)/IF(COUNT(hlstats_Frags_Kills.deaths) =0,1,COUNT(hlstats_Frags_Kills.deaths)), 0.00) AS kpd, SUM(hlstats_Frags_Kills.headshot=1) AS headshots, IFNULL(SUM(hlstats_Frags_Kills.headshot=1) / COUNT(hlstats_Frags_Kills.kills), '-') AS hpk, ROUND(CONCAT(SUM(hlstats_Frags_Kills.headshot=1)) / SUM(SUM(hlstats_Frags_Kills.headshot)) * 100, 2) AS hpercent FROM ( (SELECT f.killerId as playerId, NULL as kills, f.victimId as deaths, NULL as headshot FROM hlstats_Events_Frags f, hlstats_Servers s WHERE s.serverId=f.serverId AND s.game='tf2' AND f.victimId = 679) UNION ALL (SELECT f.victimId as playerId, f.killerId as kills, NULL as deaths, f.headshot FROM hlstats_Events_Frags f, hlstats_Servers s WHERE s.serverId=f.serverId AND s.game='tf2' AND f.killerId = 679 GROUP BY f.id) ) hlstats_Frags_Kills, hlstats_Players WHERE hlstats_Frags_Kills.playerId = hlstats_Players.playerId GROUP BY hlstats_Frags_Kills.playerId, hlstats_Frags_Kills.headshot HAVING COUNT(hlstats_Frags_Kills.kills) >= 5 Problem line: ROUND(CONCAT(SUM(hlstats_Frags_Kills.headshot=1)) / SUM(SUM(hlstats_Frags_Kills.headshot)) * 100, 2) AS hpercent Problem is...I need to get the SUM(SUM(hlstats_Frags_Kills.headshot)), which I can't seem to do. I get group by errors. Is there a way to do this in one query (without doing two long UNION table from statements)? Quote Link to comment https://forums.phpfreaks.com/topic/131253-mysql-sum-issue/ Share on other sites More sharing options...
fenway Posted November 3, 2008 Share Posted November 3, 2008 I can't comprehend that much sql at once. Quote Link to comment https://forums.phpfreaks.com/topic/131253-mysql-sum-issue/#findComment-681470 Share on other sites More sharing options...
danbopes Posted November 3, 2008 Author Share Posted November 3, 2008 I can't comprehend that much sql at once. This is exactly why...I am having trouble. Quote Link to comment https://forums.phpfreaks.com/topic/131253-mysql-sum-issue/#findComment-681485 Share on other sites More sharing options...
danbopes Posted November 3, 2008 Author Share Posted November 3, 2008 Let me see if I can make it easier: SELECT SUM(SUM(hlstats_Frags_Kills.headshot)) * 100, 2) AS hpercent FROM ( Some big query ) hlstats_Frags_Kills, hlstats_Players WHERE hlstats_Frags_Kills.playerId = hlstats_Players.playerId GROUP BY hlstats_Frags_Kills.playerId, hlstats_Frags_Kills.headshot I need to grab the SUM of the entire query to use to divide correctly. I just don't know how to do that (without grouping everything into one row). I don't know if it's possible Quote Link to comment https://forums.phpfreaks.com/topic/131253-mysql-sum-issue/#findComment-681601 Share on other sites More sharing options...
fenway Posted November 4, 2008 Share Posted November 4, 2008 I'm not sure I understand what you're trying to SUM. Quote Link to comment https://forums.phpfreaks.com/topic/131253-mysql-sum-issue/#findComment-681740 Share on other sites More sharing options...
laffin Posted November 4, 2008 Share Posted November 4, 2008 why not break it down into seperate queries than once that works work on combining them into 1 query Quote Link to comment https://forums.phpfreaks.com/topic/131253-mysql-sum-issue/#findComment-681743 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.