I have a problem how to sum the percent to be 100.00. i try use the "Round" but the result just show 99.93. Anyone got the idea?.
SELECT Sum(percent)
FROM (SELECT state,
jantina,
bilmale,
jds,
jumall,
Round(( bilmale * 100 / ( jumall ) ), 2) PERCENT,
( jds ) * 100 / ( jumall ) AS p_jdk
FROM (SELECT Timestamp(X.createdate)
dattime
,
Upper(Date_format(X.createdate, '%d %M %Y')) AS
datenegeri,
X.state,
Upper(CASE
WHEN g.ns_fender_desc = 'male' THEN 'LELAKI'
WHEN g.ns_fender_desc = 'female' THEN 'PEREMPUAN'
ELSE g.ns_fender_desc
END) jantina
,
Sum(CASE
WHEN X.male = 1 THEN 1
WHEN X.male = 0 THEN 1
ELSE 0
END) bilmale
,
(SELECT Sum(CASE
WHEN Y.male = 1 THEN 1
WHEN Y.male = 0 THEN 1
ELSE 0
END) bilmale
FROM xyuser_userext Y
JOIN tnsstate TS
ON TS.ns_state_id = Y.state
LEFT JOIN tnsgender g
ON g.ns_gender_id = Y.male
WHERE Y.statususerext IN ( '0', '1', '2', '5' )
AND Y.state = X.state
AND Date_format(X.createdate, '%d %M %Y') =
Date_format(Y.createdate, '%d %M %Y')
GROUP BY TS.ns_state_desc,
Date_format(X.createdate, '%d %M %Y')) jds,
(SELECT Sum(CASE
WHEN Y.male = 1 THEN 1
WHEN Y.male = 0 THEN 1
ELSE 0
END) bilmale
FROM xyuser_userext Y
JOIN tnsstate TS
ON TS.ns_state_id = Y.state
LEFT JOIN tnsgender g
ON g.ns_gender_id = Y.male
WHERE Y.statususerext IN ( '0', '1', '2', '5' ))jumall
FROM xyuser_userext X
JOIN tnsstate TS
ON TS.ns_state_id = X.state
LEFT JOIN tnsgender g
ON g.ns_gender_id = X.male
WHERE X.statususerext IN ( '0', '1', '2', '5' )
GROUP BY TS.ns_state_desc,
Date_format(X.createdate, '%d %M %Y'),
X.male
ORDER BY 1 ASC) AS A) AS b