Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8059307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:37:56+00:00 2026-06-05T09:37:56+00:00

I have a simple stats query in mysql. I had it working using php

  • 0

I have a simple stats query in mysql.
I had it working using php but was keen to keep it in the database so I found another question on it here. Thanks to that I have it working in mysql now.

I need to get a running total count of records submitted per day.

I have the running total working but no matter what I change it simply will not order by day.

It will order by the running total column but not the day.

Any input is appreciated.

SET @runtot:=0;
SELECT
   q1.`Day` AS 'Days of month',
   q1.`Record count` AS 'Record count',
   (@runtot := @runtot +  q1.`Record count`) AS 'rt'
FROM
   (SELECT
    FROM_UNIXTIME(tr.`tr_last_update`, '%e') AS 'Day',
    COUNT(tr.tr_id_pk) AS 'Record Count'
    FROM records_table AS tr
    GROUP BY FROM_UNIXTIME(tr.`tr_last_update`,'%e')
) AS q1
ORDER BY 'Days of month';

Days of month   Record count    rt
10                  13          13
11                  2           15
7                   255         270
8                   173         443
9                   166         609
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:37:58+00:00Added an answer on June 5, 2026 at 9:37 am

    It’s being treated as a string. Try casting to an int:

    SELECT
    q1.`Day` AS 'Days of month',
    ...
    ORDER BY CAST(q1.`Day` AS signed integer)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple mysql select query in my PHP code: $result = mysql_query(SELECT
I have made a simple chat script using jquery and AJAX but the huge
I'm using a simple mysql LIKE query like this: SELECT * FROM myTable WHERE
Currently I have a MySQL query I run in PHP and when going through
I have a simple calendar on PHP and MySQL, it stores events in a
I have a simple query which is returning records based on the field status
I have a fairly simple query that runs super fast most of the time
Let's say I have a MySQL database with 3 tables: table 1: Persons, with
I have MySQL database, where I store the following BLOB (which contains JSON object)
I know I can change the way MySQL executes a query by using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.