create a ranking and statistics with repeated database records












0














Today I want to get a help in creating scores per user in my database. I have this query:



SELECT
r1.id,
r1.nickname,
r1.fecha,
r1.bestia1,
r1.bestia2,
r1.bestia3,
r1.bestia4
r1.bestia5
FROM
reporte AS r1
INNER JOIN
( SELECT
nickname, MAX(fecha) AS max_date
FROM
reporte
GROUP BY
nickname ) AS latests_reports
ON latests_reports.nickname = r1.nickname
AND latests_reports.max_date = r1.fecha
ORDER BY
r1.fecha DESC


that's from a friend from this site who helped me in get "the last record per user in each day", based on this I am looking how to count the results in a ranking daily, weekly or monthly, in order to use statistics charts or google datastudio, I've tried the next:



select id, nickname, sum(bestia1), sum(bestia2), etc...


But its not giving the complete result wich I want. thats why I am looking for help. Additionaly I know datastudio filters where I can show many charts but still I can count completely.



for example, one player in the last 30 days reported 265 monsters killed, but when I use in datastudio my query it counts only the latest value (it can be 12). so I want to count correctly in order to use with charts



SQL records filtered with my query:



enter image description here










share|improve this question




















  • 2




    Any time you find yourself with enumerated columns, alarm bells should start ringing. Consider revising your schema
    – Strawberry
    Nov 22 at 21:58










  • Just to clarify and like a starting point, do you need to group by user (column nickname) and then get the sum of monster (column bestia1 + column bestia2 + column bestia3 + column bestia4 + column bestia5) they killed on some day (maybe the current one)? Then, later, do you need this same calculation but over the last week and month?. Also if you can add add some sample of data, and the output you expect to get from they, that will help a lot.
    – Shidersz
    Nov 23 at 2:25










  • yes, i need to put in a report who killed more monsters in the current week, the last week or last month, additionally i was thinking in something like that sum(bestia1*1),sum(bestia2*2) in order to create an "score" where each monster is counting for ranking.
    – G. Romero
    Nov 23 at 5:19
















0














Today I want to get a help in creating scores per user in my database. I have this query:



SELECT
r1.id,
r1.nickname,
r1.fecha,
r1.bestia1,
r1.bestia2,
r1.bestia3,
r1.bestia4
r1.bestia5
FROM
reporte AS r1
INNER JOIN
( SELECT
nickname, MAX(fecha) AS max_date
FROM
reporte
GROUP BY
nickname ) AS latests_reports
ON latests_reports.nickname = r1.nickname
AND latests_reports.max_date = r1.fecha
ORDER BY
r1.fecha DESC


that's from a friend from this site who helped me in get "the last record per user in each day", based on this I am looking how to count the results in a ranking daily, weekly or monthly, in order to use statistics charts or google datastudio, I've tried the next:



select id, nickname, sum(bestia1), sum(bestia2), etc...


But its not giving the complete result wich I want. thats why I am looking for help. Additionaly I know datastudio filters where I can show many charts but still I can count completely.



for example, one player in the last 30 days reported 265 monsters killed, but when I use in datastudio my query it counts only the latest value (it can be 12). so I want to count correctly in order to use with charts



SQL records filtered with my query:



enter image description here










share|improve this question




















  • 2




    Any time you find yourself with enumerated columns, alarm bells should start ringing. Consider revising your schema
    – Strawberry
    Nov 22 at 21:58










  • Just to clarify and like a starting point, do you need to group by user (column nickname) and then get the sum of monster (column bestia1 + column bestia2 + column bestia3 + column bestia4 + column bestia5) they killed on some day (maybe the current one)? Then, later, do you need this same calculation but over the last week and month?. Also if you can add add some sample of data, and the output you expect to get from they, that will help a lot.
    – Shidersz
    Nov 23 at 2:25










  • yes, i need to put in a report who killed more monsters in the current week, the last week or last month, additionally i was thinking in something like that sum(bestia1*1),sum(bestia2*2) in order to create an "score" where each monster is counting for ranking.
    – G. Romero
    Nov 23 at 5:19














0












0








0







Today I want to get a help in creating scores per user in my database. I have this query:



SELECT
r1.id,
r1.nickname,
r1.fecha,
r1.bestia1,
r1.bestia2,
r1.bestia3,
r1.bestia4
r1.bestia5
FROM
reporte AS r1
INNER JOIN
( SELECT
nickname, MAX(fecha) AS max_date
FROM
reporte
GROUP BY
nickname ) AS latests_reports
ON latests_reports.nickname = r1.nickname
AND latests_reports.max_date = r1.fecha
ORDER BY
r1.fecha DESC


that's from a friend from this site who helped me in get "the last record per user in each day", based on this I am looking how to count the results in a ranking daily, weekly or monthly, in order to use statistics charts or google datastudio, I've tried the next:



select id, nickname, sum(bestia1), sum(bestia2), etc...


But its not giving the complete result wich I want. thats why I am looking for help. Additionaly I know datastudio filters where I can show many charts but still I can count completely.



for example, one player in the last 30 days reported 265 monsters killed, but when I use in datastudio my query it counts only the latest value (it can be 12). so I want to count correctly in order to use with charts



SQL records filtered with my query:



enter image description here










share|improve this question















Today I want to get a help in creating scores per user in my database. I have this query:



SELECT
r1.id,
r1.nickname,
r1.fecha,
r1.bestia1,
r1.bestia2,
r1.bestia3,
r1.bestia4
r1.bestia5
FROM
reporte AS r1
INNER JOIN
( SELECT
nickname, MAX(fecha) AS max_date
FROM
reporte
GROUP BY
nickname ) AS latests_reports
ON latests_reports.nickname = r1.nickname
AND latests_reports.max_date = r1.fecha
ORDER BY
r1.fecha DESC


that's from a friend from this site who helped me in get "the last record per user in each day", based on this I am looking how to count the results in a ranking daily, weekly or monthly, in order to use statistics charts or google datastudio, I've tried the next:



select id, nickname, sum(bestia1), sum(bestia2), etc...


But its not giving the complete result wich I want. thats why I am looking for help. Additionaly I know datastudio filters where I can show many charts but still I can count completely.



for example, one player in the last 30 days reported 265 monsters killed, but when I use in datastudio my query it counts only the latest value (it can be 12). so I want to count correctly in order to use with charts



SQL records filtered with my query:



enter image description here







mysql sql highcharts ranking






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 2:46









Parfait

49.5k84168




49.5k84168










asked Nov 22 at 21:20









G. Romero

186




186








  • 2




    Any time you find yourself with enumerated columns, alarm bells should start ringing. Consider revising your schema
    – Strawberry
    Nov 22 at 21:58










  • Just to clarify and like a starting point, do you need to group by user (column nickname) and then get the sum of monster (column bestia1 + column bestia2 + column bestia3 + column bestia4 + column bestia5) they killed on some day (maybe the current one)? Then, later, do you need this same calculation but over the last week and month?. Also if you can add add some sample of data, and the output you expect to get from they, that will help a lot.
    – Shidersz
    Nov 23 at 2:25










  • yes, i need to put in a report who killed more monsters in the current week, the last week or last month, additionally i was thinking in something like that sum(bestia1*1),sum(bestia2*2) in order to create an "score" where each monster is counting for ranking.
    – G. Romero
    Nov 23 at 5:19














  • 2




    Any time you find yourself with enumerated columns, alarm bells should start ringing. Consider revising your schema
    – Strawberry
    Nov 22 at 21:58










  • Just to clarify and like a starting point, do you need to group by user (column nickname) and then get the sum of monster (column bestia1 + column bestia2 + column bestia3 + column bestia4 + column bestia5) they killed on some day (maybe the current one)? Then, later, do you need this same calculation but over the last week and month?. Also if you can add add some sample of data, and the output you expect to get from they, that will help a lot.
    – Shidersz
    Nov 23 at 2:25










  • yes, i need to put in a report who killed more monsters in the current week, the last week or last month, additionally i was thinking in something like that sum(bestia1*1),sum(bestia2*2) in order to create an "score" where each monster is counting for ranking.
    – G. Romero
    Nov 23 at 5:19








2




2




Any time you find yourself with enumerated columns, alarm bells should start ringing. Consider revising your schema
– Strawberry
Nov 22 at 21:58




Any time you find yourself with enumerated columns, alarm bells should start ringing. Consider revising your schema
– Strawberry
Nov 22 at 21:58












Just to clarify and like a starting point, do you need to group by user (column nickname) and then get the sum of monster (column bestia1 + column bestia2 + column bestia3 + column bestia4 + column bestia5) they killed on some day (maybe the current one)? Then, later, do you need this same calculation but over the last week and month?. Also if you can add add some sample of data, and the output you expect to get from they, that will help a lot.
– Shidersz
Nov 23 at 2:25




Just to clarify and like a starting point, do you need to group by user (column nickname) and then get the sum of monster (column bestia1 + column bestia2 + column bestia3 + column bestia4 + column bestia5) they killed on some day (maybe the current one)? Then, later, do you need this same calculation but over the last week and month?. Also if you can add add some sample of data, and the output you expect to get from they, that will help a lot.
– Shidersz
Nov 23 at 2:25












yes, i need to put in a report who killed more monsters in the current week, the last week or last month, additionally i was thinking in something like that sum(bestia1*1),sum(bestia2*2) in order to create an "score" where each monster is counting for ranking.
– G. Romero
Nov 23 at 5:19




yes, i need to put in a report who killed more monsters in the current week, the last week or last month, additionally i was thinking in something like that sum(bestia1*1),sum(bestia2*2) in order to create an "score" where each monster is counting for ranking.
– G. Romero
Nov 23 at 5:19












2 Answers
2






active

oldest

votes


















1














One general approach for get the total monsters killed by each user on the latest X days and make a score calculation like the one you propose on the commentaries can be like this:



SET @daysOnHistory = X; -- Where X should be an integer positive number (like 10).

SELECT
nickname,
SUM(bestia1) AS total_bestia1_killed,
SUM(bestia2) AS total_bestia2_killed,
SUM(bestia3) AS total_bestia3_killed,
SUM(bestia4) AS total_bestia4_killed,
SUM(bestia5) AS total_bestia5_killed,
SUM(bestia1 + bestia2 + bestia3 + bestia4 + bestia5) AS total_monsters_killed,
SUM(bestia1 + 2 * bestia2 + 3 * bestia3 + 4 * bestia4 + 5 * bestia5) AS total_score
FROM
reporte
WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY)
GROUP BY
nickname
ORDER BY
total_score DESC


Now, if you want the same calculation but only taking into account the days of the current week (assuming a week starts on Monday), you need to replace the previous WHERE clause by next one:



WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY)


Even more, if you want all the same, but only taking into account the days of the current month, you need to replace the WHERE clause by:



WHERE
MONTH(fecha) = MONTH(NOW())


For evaluate the statistics on the days of the current year, you need to replace the WHERE clause by:



WHERE
YEAR(fecha) = YEAR(NOW())


And finally, for evaluation on a specific range of days you can use, for example:



WHERE
DATE(fecha) BETWEEN CAST("2018-10-15" AS DATE) AND CAST('2018-11-10' AS DATE)


I hope this guide will help you and clarify your outlook.






share|improve this answer























  • wow this solves a lot about what i am looking!! thank you man!!!
    – G. Romero
    Nov 24 at 18:14










  • sir, how can i get the report from yesterday or x days ago? but only from these day? because i tried tu put the exact date or range of days but it sums all monsters
    – G. Romero
    Nov 26 at 14:33










  • Check the first query of my guide, but change where clause by DATE(fecha) = DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY ).
    – Shidersz
    Nov 26 at 23:25










  • Hello sir, the ranking for current week is bot working properly, i created a ranking in PHP and today i AM not getting any data
    – G. Romero
    Dec 2 at 15:40










  • @G.Romero I have updated my answer. Use this for week ranking: WHERE fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY). Tellme if it works as you expect now... Also, if you could vote me up, i will appeciate it.
    – Shidersz
    Dec 2 at 16:26



















1














This will give you number of monster killed in the last 30 days per user :



SELECT
nickname,
sum(bestia1) as bestia1,
sum(bestia2) as bestia2,
sum(bestia3) as bestia3,
sum(bestia4) as bestia4,
sum(bestia5) as bestia5
FROM
reporte
WHERE fecha >= DATE_ADD(curdate(), interval -30 day)
GROUP BY nickName
ORDER BY





share|improve this answer





















  • thankyou for that sir, i am working with this code just now in order to replace interval days per current week or last week, for example i want to get the monster killed per user this week from 19/11 to 25/11, if you know that please explain to me... thanks
    – G. Romero
    Nov 23 at 5:21










  • For monster killed between 19 to 25, replace where clause for WHERE fecha between '2018-11-19' and '2018-11-25 23:59:59' If you omit 23:59:59, you will be missing entries of the last day in the range. between '2018-11-19' and '2018-11-25' will be from 11-19 midnight to 11-25 midnight (night between 24 and 25).
    – DanB
    Nov 23 at 18:41













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%2f53438107%2fcreate-a-ranking-and-statistics-with-repeated-database-records%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














One general approach for get the total monsters killed by each user on the latest X days and make a score calculation like the one you propose on the commentaries can be like this:



SET @daysOnHistory = X; -- Where X should be an integer positive number (like 10).

SELECT
nickname,
SUM(bestia1) AS total_bestia1_killed,
SUM(bestia2) AS total_bestia2_killed,
SUM(bestia3) AS total_bestia3_killed,
SUM(bestia4) AS total_bestia4_killed,
SUM(bestia5) AS total_bestia5_killed,
SUM(bestia1 + bestia2 + bestia3 + bestia4 + bestia5) AS total_monsters_killed,
SUM(bestia1 + 2 * bestia2 + 3 * bestia3 + 4 * bestia4 + 5 * bestia5) AS total_score
FROM
reporte
WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY)
GROUP BY
nickname
ORDER BY
total_score DESC


Now, if you want the same calculation but only taking into account the days of the current week (assuming a week starts on Monday), you need to replace the previous WHERE clause by next one:



WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY)


Even more, if you want all the same, but only taking into account the days of the current month, you need to replace the WHERE clause by:



WHERE
MONTH(fecha) = MONTH(NOW())


For evaluate the statistics on the days of the current year, you need to replace the WHERE clause by:



WHERE
YEAR(fecha) = YEAR(NOW())


And finally, for evaluation on a specific range of days you can use, for example:



WHERE
DATE(fecha) BETWEEN CAST("2018-10-15" AS DATE) AND CAST('2018-11-10' AS DATE)


I hope this guide will help you and clarify your outlook.






share|improve this answer























  • wow this solves a lot about what i am looking!! thank you man!!!
    – G. Romero
    Nov 24 at 18:14










  • sir, how can i get the report from yesterday or x days ago? but only from these day? because i tried tu put the exact date or range of days but it sums all monsters
    – G. Romero
    Nov 26 at 14:33










  • Check the first query of my guide, but change where clause by DATE(fecha) = DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY ).
    – Shidersz
    Nov 26 at 23:25










  • Hello sir, the ranking for current week is bot working properly, i created a ranking in PHP and today i AM not getting any data
    – G. Romero
    Dec 2 at 15:40










  • @G.Romero I have updated my answer. Use this for week ranking: WHERE fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY). Tellme if it works as you expect now... Also, if you could vote me up, i will appeciate it.
    – Shidersz
    Dec 2 at 16:26
















1














One general approach for get the total monsters killed by each user on the latest X days and make a score calculation like the one you propose on the commentaries can be like this:



SET @daysOnHistory = X; -- Where X should be an integer positive number (like 10).

SELECT
nickname,
SUM(bestia1) AS total_bestia1_killed,
SUM(bestia2) AS total_bestia2_killed,
SUM(bestia3) AS total_bestia3_killed,
SUM(bestia4) AS total_bestia4_killed,
SUM(bestia5) AS total_bestia5_killed,
SUM(bestia1 + bestia2 + bestia3 + bestia4 + bestia5) AS total_monsters_killed,
SUM(bestia1 + 2 * bestia2 + 3 * bestia3 + 4 * bestia4 + 5 * bestia5) AS total_score
FROM
reporte
WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY)
GROUP BY
nickname
ORDER BY
total_score DESC


Now, if you want the same calculation but only taking into account the days of the current week (assuming a week starts on Monday), you need to replace the previous WHERE clause by next one:



WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY)


Even more, if you want all the same, but only taking into account the days of the current month, you need to replace the WHERE clause by:



WHERE
MONTH(fecha) = MONTH(NOW())


For evaluate the statistics on the days of the current year, you need to replace the WHERE clause by:



WHERE
YEAR(fecha) = YEAR(NOW())


And finally, for evaluation on a specific range of days you can use, for example:



WHERE
DATE(fecha) BETWEEN CAST("2018-10-15" AS DATE) AND CAST('2018-11-10' AS DATE)


I hope this guide will help you and clarify your outlook.






share|improve this answer























  • wow this solves a lot about what i am looking!! thank you man!!!
    – G. Romero
    Nov 24 at 18:14










  • sir, how can i get the report from yesterday or x days ago? but only from these day? because i tried tu put the exact date or range of days but it sums all monsters
    – G. Romero
    Nov 26 at 14:33










  • Check the first query of my guide, but change where clause by DATE(fecha) = DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY ).
    – Shidersz
    Nov 26 at 23:25










  • Hello sir, the ranking for current week is bot working properly, i created a ranking in PHP and today i AM not getting any data
    – G. Romero
    Dec 2 at 15:40










  • @G.Romero I have updated my answer. Use this for week ranking: WHERE fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY). Tellme if it works as you expect now... Also, if you could vote me up, i will appeciate it.
    – Shidersz
    Dec 2 at 16:26














1












1








1






One general approach for get the total monsters killed by each user on the latest X days and make a score calculation like the one you propose on the commentaries can be like this:



SET @daysOnHistory = X; -- Where X should be an integer positive number (like 10).

SELECT
nickname,
SUM(bestia1) AS total_bestia1_killed,
SUM(bestia2) AS total_bestia2_killed,
SUM(bestia3) AS total_bestia3_killed,
SUM(bestia4) AS total_bestia4_killed,
SUM(bestia5) AS total_bestia5_killed,
SUM(bestia1 + bestia2 + bestia3 + bestia4 + bestia5) AS total_monsters_killed,
SUM(bestia1 + 2 * bestia2 + 3 * bestia3 + 4 * bestia4 + 5 * bestia5) AS total_score
FROM
reporte
WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY)
GROUP BY
nickname
ORDER BY
total_score DESC


Now, if you want the same calculation but only taking into account the days of the current week (assuming a week starts on Monday), you need to replace the previous WHERE clause by next one:



WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY)


Even more, if you want all the same, but only taking into account the days of the current month, you need to replace the WHERE clause by:



WHERE
MONTH(fecha) = MONTH(NOW())


For evaluate the statistics on the days of the current year, you need to replace the WHERE clause by:



WHERE
YEAR(fecha) = YEAR(NOW())


And finally, for evaluation on a specific range of days you can use, for example:



WHERE
DATE(fecha) BETWEEN CAST("2018-10-15" AS DATE) AND CAST('2018-11-10' AS DATE)


I hope this guide will help you and clarify your outlook.






share|improve this answer














One general approach for get the total monsters killed by each user on the latest X days and make a score calculation like the one you propose on the commentaries can be like this:



SET @daysOnHistory = X; -- Where X should be an integer positive number (like 10).

SELECT
nickname,
SUM(bestia1) AS total_bestia1_killed,
SUM(bestia2) AS total_bestia2_killed,
SUM(bestia3) AS total_bestia3_killed,
SUM(bestia4) AS total_bestia4_killed,
SUM(bestia5) AS total_bestia5_killed,
SUM(bestia1 + bestia2 + bestia3 + bestia4 + bestia5) AS total_monsters_killed,
SUM(bestia1 + 2 * bestia2 + 3 * bestia3 + 4 * bestia4 + 5 * bestia5) AS total_score
FROM
reporte
WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY)
GROUP BY
nickname
ORDER BY
total_score DESC


Now, if you want the same calculation but only taking into account the days of the current week (assuming a week starts on Monday), you need to replace the previous WHERE clause by next one:



WHERE
fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY)


Even more, if you want all the same, but only taking into account the days of the current month, you need to replace the WHERE clause by:



WHERE
MONTH(fecha) = MONTH(NOW())


For evaluate the statistics on the days of the current year, you need to replace the WHERE clause by:



WHERE
YEAR(fecha) = YEAR(NOW())


And finally, for evaluation on a specific range of days you can use, for example:



WHERE
DATE(fecha) BETWEEN CAST("2018-10-15" AS DATE) AND CAST('2018-11-10' AS DATE)


I hope this guide will help you and clarify your outlook.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 2 at 16:24

























answered Nov 23 at 21:58









Shidersz

3,5192525




3,5192525












  • wow this solves a lot about what i am looking!! thank you man!!!
    – G. Romero
    Nov 24 at 18:14










  • sir, how can i get the report from yesterday or x days ago? but only from these day? because i tried tu put the exact date or range of days but it sums all monsters
    – G. Romero
    Nov 26 at 14:33










  • Check the first query of my guide, but change where clause by DATE(fecha) = DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY ).
    – Shidersz
    Nov 26 at 23:25










  • Hello sir, the ranking for current week is bot working properly, i created a ranking in PHP and today i AM not getting any data
    – G. Romero
    Dec 2 at 15:40










  • @G.Romero I have updated my answer. Use this for week ranking: WHERE fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY). Tellme if it works as you expect now... Also, if you could vote me up, i will appeciate it.
    – Shidersz
    Dec 2 at 16:26


















  • wow this solves a lot about what i am looking!! thank you man!!!
    – G. Romero
    Nov 24 at 18:14










  • sir, how can i get the report from yesterday or x days ago? but only from these day? because i tried tu put the exact date or range of days but it sums all monsters
    – G. Romero
    Nov 26 at 14:33










  • Check the first query of my guide, but change where clause by DATE(fecha) = DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY ).
    – Shidersz
    Nov 26 at 23:25










  • Hello sir, the ranking for current week is bot working properly, i created a ranking in PHP and today i AM not getting any data
    – G. Romero
    Dec 2 at 15:40










  • @G.Romero I have updated my answer. Use this for week ranking: WHERE fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY). Tellme if it works as you expect now... Also, if you could vote me up, i will appeciate it.
    – Shidersz
    Dec 2 at 16:26
















wow this solves a lot about what i am looking!! thank you man!!!
– G. Romero
Nov 24 at 18:14




wow this solves a lot about what i am looking!! thank you man!!!
– G. Romero
Nov 24 at 18:14












sir, how can i get the report from yesterday or x days ago? but only from these day? because i tried tu put the exact date or range of days but it sums all monsters
– G. Romero
Nov 26 at 14:33




sir, how can i get the report from yesterday or x days ago? but only from these day? because i tried tu put the exact date or range of days but it sums all monsters
– G. Romero
Nov 26 at 14:33












Check the first query of my guide, but change where clause by DATE(fecha) = DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY ).
– Shidersz
Nov 26 at 23:25




Check the first query of my guide, but change where clause by DATE(fecha) = DATE_ADD(DATE(NOW()), INTERVAL -@daysOnHistory DAY ).
– Shidersz
Nov 26 at 23:25












Hello sir, the ranking for current week is bot working properly, i created a ranking in PHP and today i AM not getting any data
– G. Romero
Dec 2 at 15:40




Hello sir, the ranking for current week is bot working properly, i created a ranking in PHP and today i AM not getting any data
– G. Romero
Dec 2 at 15:40












@G.Romero I have updated my answer. Use this for week ranking: WHERE fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY). Tellme if it works as you expect now... Also, if you could vote me up, i will appeciate it.
– Shidersz
Dec 2 at 16:26




@G.Romero I have updated my answer. Use this for week ranking: WHERE fecha >= DATE_ADD(DATE(NOW()), INTERVAL -WEEKDAY(NOW()) DAY). Tellme if it works as you expect now... Also, if you could vote me up, i will appeciate it.
– Shidersz
Dec 2 at 16:26













1














This will give you number of monster killed in the last 30 days per user :



SELECT
nickname,
sum(bestia1) as bestia1,
sum(bestia2) as bestia2,
sum(bestia3) as bestia3,
sum(bestia4) as bestia4,
sum(bestia5) as bestia5
FROM
reporte
WHERE fecha >= DATE_ADD(curdate(), interval -30 day)
GROUP BY nickName
ORDER BY





share|improve this answer





















  • thankyou for that sir, i am working with this code just now in order to replace interval days per current week or last week, for example i want to get the monster killed per user this week from 19/11 to 25/11, if you know that please explain to me... thanks
    – G. Romero
    Nov 23 at 5:21










  • For monster killed between 19 to 25, replace where clause for WHERE fecha between '2018-11-19' and '2018-11-25 23:59:59' If you omit 23:59:59, you will be missing entries of the last day in the range. between '2018-11-19' and '2018-11-25' will be from 11-19 midnight to 11-25 midnight (night between 24 and 25).
    – DanB
    Nov 23 at 18:41


















1














This will give you number of monster killed in the last 30 days per user :



SELECT
nickname,
sum(bestia1) as bestia1,
sum(bestia2) as bestia2,
sum(bestia3) as bestia3,
sum(bestia4) as bestia4,
sum(bestia5) as bestia5
FROM
reporte
WHERE fecha >= DATE_ADD(curdate(), interval -30 day)
GROUP BY nickName
ORDER BY





share|improve this answer





















  • thankyou for that sir, i am working with this code just now in order to replace interval days per current week or last week, for example i want to get the monster killed per user this week from 19/11 to 25/11, if you know that please explain to me... thanks
    – G. Romero
    Nov 23 at 5:21










  • For monster killed between 19 to 25, replace where clause for WHERE fecha between '2018-11-19' and '2018-11-25 23:59:59' If you omit 23:59:59, you will be missing entries of the last day in the range. between '2018-11-19' and '2018-11-25' will be from 11-19 midnight to 11-25 midnight (night between 24 and 25).
    – DanB
    Nov 23 at 18:41
















1












1








1






This will give you number of monster killed in the last 30 days per user :



SELECT
nickname,
sum(bestia1) as bestia1,
sum(bestia2) as bestia2,
sum(bestia3) as bestia3,
sum(bestia4) as bestia4,
sum(bestia5) as bestia5
FROM
reporte
WHERE fecha >= DATE_ADD(curdate(), interval -30 day)
GROUP BY nickName
ORDER BY





share|improve this answer












This will give you number of monster killed in the last 30 days per user :



SELECT
nickname,
sum(bestia1) as bestia1,
sum(bestia2) as bestia2,
sum(bestia3) as bestia3,
sum(bestia4) as bestia4,
sum(bestia5) as bestia5
FROM
reporte
WHERE fecha >= DATE_ADD(curdate(), interval -30 day)
GROUP BY nickName
ORDER BY






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 at 3:33









DanB

1,3911114




1,3911114












  • thankyou for that sir, i am working with this code just now in order to replace interval days per current week or last week, for example i want to get the monster killed per user this week from 19/11 to 25/11, if you know that please explain to me... thanks
    – G. Romero
    Nov 23 at 5:21










  • For monster killed between 19 to 25, replace where clause for WHERE fecha between '2018-11-19' and '2018-11-25 23:59:59' If you omit 23:59:59, you will be missing entries of the last day in the range. between '2018-11-19' and '2018-11-25' will be from 11-19 midnight to 11-25 midnight (night between 24 and 25).
    – DanB
    Nov 23 at 18:41




















  • thankyou for that sir, i am working with this code just now in order to replace interval days per current week or last week, for example i want to get the monster killed per user this week from 19/11 to 25/11, if you know that please explain to me... thanks
    – G. Romero
    Nov 23 at 5:21










  • For monster killed between 19 to 25, replace where clause for WHERE fecha between '2018-11-19' and '2018-11-25 23:59:59' If you omit 23:59:59, you will be missing entries of the last day in the range. between '2018-11-19' and '2018-11-25' will be from 11-19 midnight to 11-25 midnight (night between 24 and 25).
    – DanB
    Nov 23 at 18:41


















thankyou for that sir, i am working with this code just now in order to replace interval days per current week or last week, for example i want to get the monster killed per user this week from 19/11 to 25/11, if you know that please explain to me... thanks
– G. Romero
Nov 23 at 5:21




thankyou for that sir, i am working with this code just now in order to replace interval days per current week or last week, for example i want to get the monster killed per user this week from 19/11 to 25/11, if you know that please explain to me... thanks
– G. Romero
Nov 23 at 5:21












For monster killed between 19 to 25, replace where clause for WHERE fecha between '2018-11-19' and '2018-11-25 23:59:59' If you omit 23:59:59, you will be missing entries of the last day in the range. between '2018-11-19' and '2018-11-25' will be from 11-19 midnight to 11-25 midnight (night between 24 and 25).
– DanB
Nov 23 at 18:41






For monster killed between 19 to 25, replace where clause for WHERE fecha between '2018-11-19' and '2018-11-25 23:59:59' If you omit 23:59:59, you will be missing entries of the last day in the range. between '2018-11-19' and '2018-11-25' will be from 11-19 midnight to 11-25 midnight (night between 24 and 25).
– DanB
Nov 23 at 18:41




















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53438107%2fcreate-a-ranking-and-statistics-with-repeated-database-records%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

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo