Mysql calculate with the max() value










1















I'm a bit stuck cause am not sure if I am looking the wrong way casue I can't find anything related to what I am looking for. So I want to give an example for what I am trying to do. NOTE: not real scenario.



I have a count on a field:



SELECT count(user_id) 
FROM usersgroups
group by user_id


Now I want to make a calc with the max value from the count. Something like:



SELECT count(user_id) as count, 
SUM(max(count(user_id)) / count(user_id)) as blub
FROM usergroups
group by user_id


But I get error invalid use of group function cause I think I cant use the COUNT() function inside the SUM function?



So is there any other way to make that calculation.



P.S. the calc is for calculating the percentage of the max value to the record/current value.



UPDATE



So what I expect is a percentage like



 count | percentage 
5 | 1
4 | 0.8
3 | 0.6
2 | 0.3
1 | 0.2


  • 5/5 = 1

  • 4/5 = 0.8

  • 3/5 = 0.6

  • 2/5 = 0.4

  • 1/5 = 0.2









share|improve this question



















  • 5





    "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

    – Raymond Nijland
    Nov 14 '18 at 10:24






  • 1





    Please read the link which Raymond has shared. Some minimal and relevant sample data and expected output will be helpful for generating quick response from the community :)

    – Madhur Bhaiya
    Nov 14 '18 at 10:37












  • I have added an example output. If that is not enough i will create a example db

    – Niels Lucas
    Nov 14 '18 at 10:45











  • in my SQL that I wrote: SELECT count(user_id) as count. So its an alias

    – Niels Lucas
    Nov 14 '18 at 11:05
















1















I'm a bit stuck cause am not sure if I am looking the wrong way casue I can't find anything related to what I am looking for. So I want to give an example for what I am trying to do. NOTE: not real scenario.



I have a count on a field:



SELECT count(user_id) 
FROM usersgroups
group by user_id


Now I want to make a calc with the max value from the count. Something like:



SELECT count(user_id) as count, 
SUM(max(count(user_id)) / count(user_id)) as blub
FROM usergroups
group by user_id


But I get error invalid use of group function cause I think I cant use the COUNT() function inside the SUM function?



So is there any other way to make that calculation.



P.S. the calc is for calculating the percentage of the max value to the record/current value.



UPDATE



So what I expect is a percentage like



 count | percentage 
5 | 1
4 | 0.8
3 | 0.6
2 | 0.3
1 | 0.2


  • 5/5 = 1

  • 4/5 = 0.8

  • 3/5 = 0.6

  • 2/5 = 0.4

  • 1/5 = 0.2









share|improve this question



















  • 5





    "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

    – Raymond Nijland
    Nov 14 '18 at 10:24






  • 1





    Please read the link which Raymond has shared. Some minimal and relevant sample data and expected output will be helpful for generating quick response from the community :)

    – Madhur Bhaiya
    Nov 14 '18 at 10:37












  • I have added an example output. If that is not enough i will create a example db

    – Niels Lucas
    Nov 14 '18 at 10:45











  • in my SQL that I wrote: SELECT count(user_id) as count. So its an alias

    – Niels Lucas
    Nov 14 '18 at 11:05














1












1








1


0






I'm a bit stuck cause am not sure if I am looking the wrong way casue I can't find anything related to what I am looking for. So I want to give an example for what I am trying to do. NOTE: not real scenario.



I have a count on a field:



SELECT count(user_id) 
FROM usersgroups
group by user_id


Now I want to make a calc with the max value from the count. Something like:



SELECT count(user_id) as count, 
SUM(max(count(user_id)) / count(user_id)) as blub
FROM usergroups
group by user_id


But I get error invalid use of group function cause I think I cant use the COUNT() function inside the SUM function?



So is there any other way to make that calculation.



P.S. the calc is for calculating the percentage of the max value to the record/current value.



UPDATE



So what I expect is a percentage like



 count | percentage 
5 | 1
4 | 0.8
3 | 0.6
2 | 0.3
1 | 0.2


  • 5/5 = 1

  • 4/5 = 0.8

  • 3/5 = 0.6

  • 2/5 = 0.4

  • 1/5 = 0.2









share|improve this question
















I'm a bit stuck cause am not sure if I am looking the wrong way casue I can't find anything related to what I am looking for. So I want to give an example for what I am trying to do. NOTE: not real scenario.



I have a count on a field:



SELECT count(user_id) 
FROM usersgroups
group by user_id


Now I want to make a calc with the max value from the count. Something like:



SELECT count(user_id) as count, 
SUM(max(count(user_id)) / count(user_id)) as blub
FROM usergroups
group by user_id


But I get error invalid use of group function cause I think I cant use the COUNT() function inside the SUM function?



So is there any other way to make that calculation.



P.S. the calc is for calculating the percentage of the max value to the record/current value.



UPDATE



So what I expect is a percentage like



 count | percentage 
5 | 1
4 | 0.8
3 | 0.6
2 | 0.3
1 | 0.2


  • 5/5 = 1

  • 4/5 = 0.8

  • 3/5 = 0.6

  • 2/5 = 0.4

  • 1/5 = 0.2






mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 10:47









Madhur Bhaiya

19.6k62236




19.6k62236










asked Nov 14 '18 at 10:18









Niels LucasNiels Lucas

721113




721113







  • 5





    "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

    – Raymond Nijland
    Nov 14 '18 at 10:24






  • 1





    Please read the link which Raymond has shared. Some minimal and relevant sample data and expected output will be helpful for generating quick response from the community :)

    – Madhur Bhaiya
    Nov 14 '18 at 10:37












  • I have added an example output. If that is not enough i will create a example db

    – Niels Lucas
    Nov 14 '18 at 10:45











  • in my SQL that I wrote: SELECT count(user_id) as count. So its an alias

    – Niels Lucas
    Nov 14 '18 at 11:05













  • 5





    "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

    – Raymond Nijland
    Nov 14 '18 at 10:24






  • 1





    Please read the link which Raymond has shared. Some minimal and relevant sample data and expected output will be helpful for generating quick response from the community :)

    – Madhur Bhaiya
    Nov 14 '18 at 10:37












  • I have added an example output. If that is not enough i will create a example db

    – Niels Lucas
    Nov 14 '18 at 10:45











  • in my SQL that I wrote: SELECT count(user_id) as count. So its an alias

    – Niels Lucas
    Nov 14 '18 at 11:05








5




5





"Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

– Raymond Nijland
Nov 14 '18 at 10:24





"Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…

– Raymond Nijland
Nov 14 '18 at 10:24




1




1





Please read the link which Raymond has shared. Some minimal and relevant sample data and expected output will be helpful for generating quick response from the community :)

– Madhur Bhaiya
Nov 14 '18 at 10:37






Please read the link which Raymond has shared. Some minimal and relevant sample data and expected output will be helpful for generating quick response from the community :)

– Madhur Bhaiya
Nov 14 '18 at 10:37














I have added an example output. If that is not enough i will create a example db

– Niels Lucas
Nov 14 '18 at 10:45





I have added an example output. If that is not enough i will create a example db

– Niels Lucas
Nov 14 '18 at 10:45













in my SQL that I wrote: SELECT count(user_id) as count. So its an alias

– Niels Lucas
Nov 14 '18 at 11:05






in my SQL that I wrote: SELECT count(user_id) as count. So its an alias

– Niels Lucas
Nov 14 '18 at 11:05













2 Answers
2






active

oldest

votes


















1














  • In a separate Derived Table, you can fetch the maximum count value out of all the counts. I have simply used ORDER BY COUNT(user_id) DESC LIMIT 1 to fetch the same.


  • CROSS JOIN this result-set with the usergroups table, so that every row in the usergroups table has access to the maximum count value.

  • Now, you can simply use the GROUP BY and appropriate aggregation to determine the "percent".

  • Note that, for GROUP BY to be valid, SELECT clause must contain either aggregated columns/expressions only, or the columns specified in the GROUP BY clause. That is why MAX() is used over the maximum count value. Since that value is only a scalar, so MAX() will return the same value only.

Try the following:



SELECT
ug.user_id,
COUNT(ug.user_id) AS user_count,
COUNT(ug.user_id) / MAX(mcnt.count) AS percent
FROM
usergroups AS ug
CROSS JOIN
(
SELECT COUNT(user_id) AS count
FROM usersgroups
GROUP BY user_id
ORDER BY COUNT(user_id) DESC LIMIT 1
) AS mcnt
GROUP BY ug.user_id
ORDER BY user_count DESC





share|improve this answer

























  • That worked, thank you! Am gonna dissect this code and try to add it in my real scenario. Thats a query thats alot larger and alot more going on. But this will help me alot I think. So again thank you!

    – Niels Lucas
    Nov 14 '18 at 11:22







  • 1





    @NielsLucas happy to help. Feel free to ask any questions later with your larger query; on how to accomodate this into there. I have added explanation; it should be handy.

    – Madhur Bhaiya
    Nov 14 '18 at 11:23











  • @NielsLucas now I look back at my answer; I had unnecessarily complicated it. Please check at the revised (and optimized) solution now.

    – Madhur Bhaiya
    Nov 14 '18 at 11:46











  • your new version always returns 1.000 percent. Typo?

    – Niels Lucas
    Nov 14 '18 at 12:31






  • 1





    Its ok. I did it. It works, so again, thank you :)

    – Niels Lucas
    Nov 14 '18 at 12:34


















0














Count available user_id as subquery, then divide user_id values by the sum of count.



 select user_id/ sum(count) as percentage 
from(
select count(user_id) as count , user_id
from usergroups
where user_id != 0
group by user_id
) as A
group by count, user_id





share|improve this answer

























  • First of all i get an error cause mysql doesn't like the [count], so i removed the . And the percentage is always 0.0001. So that is not accurate.

    – Niels Lucas
    Nov 14 '18 at 11:07












  • And now? had division in the wrong order :)

    – Olayinka O
    Nov 14 '18 at 11:15











  • it does work, but I get percentage like 10241.0000. Thats not correct... max percentage should be 1 and others should be between 0.0 - 0.9

    – Niels Lucas
    Nov 14 '18 at 12:33










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297818%2fmysql-calculate-with-the-max-value%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














  • In a separate Derived Table, you can fetch the maximum count value out of all the counts. I have simply used ORDER BY COUNT(user_id) DESC LIMIT 1 to fetch the same.


  • CROSS JOIN this result-set with the usergroups table, so that every row in the usergroups table has access to the maximum count value.

  • Now, you can simply use the GROUP BY and appropriate aggregation to determine the "percent".

  • Note that, for GROUP BY to be valid, SELECT clause must contain either aggregated columns/expressions only, or the columns specified in the GROUP BY clause. That is why MAX() is used over the maximum count value. Since that value is only a scalar, so MAX() will return the same value only.

Try the following:



SELECT
ug.user_id,
COUNT(ug.user_id) AS user_count,
COUNT(ug.user_id) / MAX(mcnt.count) AS percent
FROM
usergroups AS ug
CROSS JOIN
(
SELECT COUNT(user_id) AS count
FROM usersgroups
GROUP BY user_id
ORDER BY COUNT(user_id) DESC LIMIT 1
) AS mcnt
GROUP BY ug.user_id
ORDER BY user_count DESC





share|improve this answer

























  • That worked, thank you! Am gonna dissect this code and try to add it in my real scenario. Thats a query thats alot larger and alot more going on. But this will help me alot I think. So again thank you!

    – Niels Lucas
    Nov 14 '18 at 11:22







  • 1





    @NielsLucas happy to help. Feel free to ask any questions later with your larger query; on how to accomodate this into there. I have added explanation; it should be handy.

    – Madhur Bhaiya
    Nov 14 '18 at 11:23











  • @NielsLucas now I look back at my answer; I had unnecessarily complicated it. Please check at the revised (and optimized) solution now.

    – Madhur Bhaiya
    Nov 14 '18 at 11:46











  • your new version always returns 1.000 percent. Typo?

    – Niels Lucas
    Nov 14 '18 at 12:31






  • 1





    Its ok. I did it. It works, so again, thank you :)

    – Niels Lucas
    Nov 14 '18 at 12:34















1














  • In a separate Derived Table, you can fetch the maximum count value out of all the counts. I have simply used ORDER BY COUNT(user_id) DESC LIMIT 1 to fetch the same.


  • CROSS JOIN this result-set with the usergroups table, so that every row in the usergroups table has access to the maximum count value.

  • Now, you can simply use the GROUP BY and appropriate aggregation to determine the "percent".

  • Note that, for GROUP BY to be valid, SELECT clause must contain either aggregated columns/expressions only, or the columns specified in the GROUP BY clause. That is why MAX() is used over the maximum count value. Since that value is only a scalar, so MAX() will return the same value only.

Try the following:



SELECT
ug.user_id,
COUNT(ug.user_id) AS user_count,
COUNT(ug.user_id) / MAX(mcnt.count) AS percent
FROM
usergroups AS ug
CROSS JOIN
(
SELECT COUNT(user_id) AS count
FROM usersgroups
GROUP BY user_id
ORDER BY COUNT(user_id) DESC LIMIT 1
) AS mcnt
GROUP BY ug.user_id
ORDER BY user_count DESC





share|improve this answer

























  • That worked, thank you! Am gonna dissect this code and try to add it in my real scenario. Thats a query thats alot larger and alot more going on. But this will help me alot I think. So again thank you!

    – Niels Lucas
    Nov 14 '18 at 11:22







  • 1





    @NielsLucas happy to help. Feel free to ask any questions later with your larger query; on how to accomodate this into there. I have added explanation; it should be handy.

    – Madhur Bhaiya
    Nov 14 '18 at 11:23











  • @NielsLucas now I look back at my answer; I had unnecessarily complicated it. Please check at the revised (and optimized) solution now.

    – Madhur Bhaiya
    Nov 14 '18 at 11:46











  • your new version always returns 1.000 percent. Typo?

    – Niels Lucas
    Nov 14 '18 at 12:31






  • 1





    Its ok. I did it. It works, so again, thank you :)

    – Niels Lucas
    Nov 14 '18 at 12:34













1












1








1







  • In a separate Derived Table, you can fetch the maximum count value out of all the counts. I have simply used ORDER BY COUNT(user_id) DESC LIMIT 1 to fetch the same.


  • CROSS JOIN this result-set with the usergroups table, so that every row in the usergroups table has access to the maximum count value.

  • Now, you can simply use the GROUP BY and appropriate aggregation to determine the "percent".

  • Note that, for GROUP BY to be valid, SELECT clause must contain either aggregated columns/expressions only, or the columns specified in the GROUP BY clause. That is why MAX() is used over the maximum count value. Since that value is only a scalar, so MAX() will return the same value only.

Try the following:



SELECT
ug.user_id,
COUNT(ug.user_id) AS user_count,
COUNT(ug.user_id) / MAX(mcnt.count) AS percent
FROM
usergroups AS ug
CROSS JOIN
(
SELECT COUNT(user_id) AS count
FROM usersgroups
GROUP BY user_id
ORDER BY COUNT(user_id) DESC LIMIT 1
) AS mcnt
GROUP BY ug.user_id
ORDER BY user_count DESC





share|improve this answer















  • In a separate Derived Table, you can fetch the maximum count value out of all the counts. I have simply used ORDER BY COUNT(user_id) DESC LIMIT 1 to fetch the same.


  • CROSS JOIN this result-set with the usergroups table, so that every row in the usergroups table has access to the maximum count value.

  • Now, you can simply use the GROUP BY and appropriate aggregation to determine the "percent".

  • Note that, for GROUP BY to be valid, SELECT clause must contain either aggregated columns/expressions only, or the columns specified in the GROUP BY clause. That is why MAX() is used over the maximum count value. Since that value is only a scalar, so MAX() will return the same value only.

Try the following:



SELECT
ug.user_id,
COUNT(ug.user_id) AS user_count,
COUNT(ug.user_id) / MAX(mcnt.count) AS percent
FROM
usergroups AS ug
CROSS JOIN
(
SELECT COUNT(user_id) AS count
FROM usersgroups
GROUP BY user_id
ORDER BY COUNT(user_id) DESC LIMIT 1
) AS mcnt
GROUP BY ug.user_id
ORDER BY user_count DESC






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 12:32

























answered Nov 14 '18 at 11:15









Madhur BhaiyaMadhur Bhaiya

19.6k62236




19.6k62236












  • That worked, thank you! Am gonna dissect this code and try to add it in my real scenario. Thats a query thats alot larger and alot more going on. But this will help me alot I think. So again thank you!

    – Niels Lucas
    Nov 14 '18 at 11:22







  • 1





    @NielsLucas happy to help. Feel free to ask any questions later with your larger query; on how to accomodate this into there. I have added explanation; it should be handy.

    – Madhur Bhaiya
    Nov 14 '18 at 11:23











  • @NielsLucas now I look back at my answer; I had unnecessarily complicated it. Please check at the revised (and optimized) solution now.

    – Madhur Bhaiya
    Nov 14 '18 at 11:46











  • your new version always returns 1.000 percent. Typo?

    – Niels Lucas
    Nov 14 '18 at 12:31






  • 1





    Its ok. I did it. It works, so again, thank you :)

    – Niels Lucas
    Nov 14 '18 at 12:34

















  • That worked, thank you! Am gonna dissect this code and try to add it in my real scenario. Thats a query thats alot larger and alot more going on. But this will help me alot I think. So again thank you!

    – Niels Lucas
    Nov 14 '18 at 11:22







  • 1





    @NielsLucas happy to help. Feel free to ask any questions later with your larger query; on how to accomodate this into there. I have added explanation; it should be handy.

    – Madhur Bhaiya
    Nov 14 '18 at 11:23











  • @NielsLucas now I look back at my answer; I had unnecessarily complicated it. Please check at the revised (and optimized) solution now.

    – Madhur Bhaiya
    Nov 14 '18 at 11:46











  • your new version always returns 1.000 percent. Typo?

    – Niels Lucas
    Nov 14 '18 at 12:31






  • 1





    Its ok. I did it. It works, so again, thank you :)

    – Niels Lucas
    Nov 14 '18 at 12:34
















That worked, thank you! Am gonna dissect this code and try to add it in my real scenario. Thats a query thats alot larger and alot more going on. But this will help me alot I think. So again thank you!

– Niels Lucas
Nov 14 '18 at 11:22






That worked, thank you! Am gonna dissect this code and try to add it in my real scenario. Thats a query thats alot larger and alot more going on. But this will help me alot I think. So again thank you!

– Niels Lucas
Nov 14 '18 at 11:22





1




1





@NielsLucas happy to help. Feel free to ask any questions later with your larger query; on how to accomodate this into there. I have added explanation; it should be handy.

– Madhur Bhaiya
Nov 14 '18 at 11:23





@NielsLucas happy to help. Feel free to ask any questions later with your larger query; on how to accomodate this into there. I have added explanation; it should be handy.

– Madhur Bhaiya
Nov 14 '18 at 11:23













@NielsLucas now I look back at my answer; I had unnecessarily complicated it. Please check at the revised (and optimized) solution now.

– Madhur Bhaiya
Nov 14 '18 at 11:46





@NielsLucas now I look back at my answer; I had unnecessarily complicated it. Please check at the revised (and optimized) solution now.

– Madhur Bhaiya
Nov 14 '18 at 11:46













your new version always returns 1.000 percent. Typo?

– Niels Lucas
Nov 14 '18 at 12:31





your new version always returns 1.000 percent. Typo?

– Niels Lucas
Nov 14 '18 at 12:31




1




1





Its ok. I did it. It works, so again, thank you :)

– Niels Lucas
Nov 14 '18 at 12:34





Its ok. I did it. It works, so again, thank you :)

– Niels Lucas
Nov 14 '18 at 12:34













0














Count available user_id as subquery, then divide user_id values by the sum of count.



 select user_id/ sum(count) as percentage 
from(
select count(user_id) as count , user_id
from usergroups
where user_id != 0
group by user_id
) as A
group by count, user_id





share|improve this answer

























  • First of all i get an error cause mysql doesn't like the [count], so i removed the . And the percentage is always 0.0001. So that is not accurate.

    – Niels Lucas
    Nov 14 '18 at 11:07












  • And now? had division in the wrong order :)

    – Olayinka O
    Nov 14 '18 at 11:15











  • it does work, but I get percentage like 10241.0000. Thats not correct... max percentage should be 1 and others should be between 0.0 - 0.9

    – Niels Lucas
    Nov 14 '18 at 12:33















0














Count available user_id as subquery, then divide user_id values by the sum of count.



 select user_id/ sum(count) as percentage 
from(
select count(user_id) as count , user_id
from usergroups
where user_id != 0
group by user_id
) as A
group by count, user_id





share|improve this answer

























  • First of all i get an error cause mysql doesn't like the [count], so i removed the . And the percentage is always 0.0001. So that is not accurate.

    – Niels Lucas
    Nov 14 '18 at 11:07












  • And now? had division in the wrong order :)

    – Olayinka O
    Nov 14 '18 at 11:15











  • it does work, but I get percentage like 10241.0000. Thats not correct... max percentage should be 1 and others should be between 0.0 - 0.9

    – Niels Lucas
    Nov 14 '18 at 12:33













0












0








0







Count available user_id as subquery, then divide user_id values by the sum of count.



 select user_id/ sum(count) as percentage 
from(
select count(user_id) as count , user_id
from usergroups
where user_id != 0
group by user_id
) as A
group by count, user_id





share|improve this answer















Count available user_id as subquery, then divide user_id values by the sum of count.



 select user_id/ sum(count) as percentage 
from(
select count(user_id) as count , user_id
from usergroups
where user_id != 0
group by user_id
) as A
group by count, user_id






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 11:14

























answered Nov 14 '18 at 10:48









Olayinka OOlayinka O

623320




623320












  • First of all i get an error cause mysql doesn't like the [count], so i removed the . And the percentage is always 0.0001. So that is not accurate.

    – Niels Lucas
    Nov 14 '18 at 11:07












  • And now? had division in the wrong order :)

    – Olayinka O
    Nov 14 '18 at 11:15











  • it does work, but I get percentage like 10241.0000. Thats not correct... max percentage should be 1 and others should be between 0.0 - 0.9

    – Niels Lucas
    Nov 14 '18 at 12:33

















  • First of all i get an error cause mysql doesn't like the [count], so i removed the . And the percentage is always 0.0001. So that is not accurate.

    – Niels Lucas
    Nov 14 '18 at 11:07












  • And now? had division in the wrong order :)

    – Olayinka O
    Nov 14 '18 at 11:15











  • it does work, but I get percentage like 10241.0000. Thats not correct... max percentage should be 1 and others should be between 0.0 - 0.9

    – Niels Lucas
    Nov 14 '18 at 12:33
















First of all i get an error cause mysql doesn't like the [count], so i removed the . And the percentage is always 0.0001. So that is not accurate.

– Niels Lucas
Nov 14 '18 at 11:07






First of all i get an error cause mysql doesn't like the [count], so i removed the . And the percentage is always 0.0001. So that is not accurate.

– Niels Lucas
Nov 14 '18 at 11:07














And now? had division in the wrong order :)

– Olayinka O
Nov 14 '18 at 11:15





And now? had division in the wrong order :)

– Olayinka O
Nov 14 '18 at 11:15













it does work, but I get percentage like 10241.0000. Thats not correct... max percentage should be 1 and others should be between 0.0 - 0.9

– Niels Lucas
Nov 14 '18 at 12:33





it does work, but I get percentage like 10241.0000. Thats not correct... max percentage should be 1 and others should be between 0.0 - 0.9

– Niels Lucas
Nov 14 '18 at 12:33

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297818%2fmysql-calculate-with-the-max-value%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo