Jump to content

Recommended Posts

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)?

Link to comment
https://forums.phpfreaks.com/topic/131253-mysql-sum-issue/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/131253-mysql-sum-issue/#findComment-681601
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.