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

  • SEARCH
  • Home
  • 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 8280761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:47:55+00:00 2026-06-08T09:47:55+00:00

I have a table with messages per user: users —————- user_id messages —————- 725

  • 0

I have a table with messages per user:

users
----------------
user_id messages
----------------
  725       0
   30       0
 1436       1
10454       4
    .       .
    .       .
 1507      901

The table contains 74,500 users. The table is sorted ASC for the numer of messages. I now want to count the number of tweets per percentile, so:

SELECT SUM(messages) FROM users LIMIT     0, 745;
SELECT SUM(messages) FROM users LIMIT   745, 745;
SELECT SUM(messages) FROM users LIMIT  1490, 745;
.
.
SELECT SUM(messages) FROM users LIMIT 73755, 745;

I can do this, no problem. And I could write a script to fire the queries to the database. But I was wondering, isn’t it possible to let MySQL output the total number of messages per usergroup? So the output would be something like

group  users         total_messages
-----------------------------------
  1       0 - 745     451
  2     745 - 1490   5627
  .      .      .      .
  .      .      .      .
100   73755 - 74500  2654
  • 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-08T09:47:57+00:00Added an answer on June 8, 2026 at 9:47 am

    try this:

    select group_id,concat(MIN(user_id) ,'-',MAX(user_id)) as users,
    SUM(messages) as messages  
    from
      (SELECT ceil(@rownum:= @rownum+1/745 ) AS group_id,user_id,messages
      FROM users, (SELECT @rownum:=0) r
      order by user_id)a
      group by group_id
    

    if you want group range also to be displayed , you could do this

    select group_id,concat(MIN(rownum) ,'-',MAX(rownum)) as groups,
    concat(MIN(user_id) ,'-',MAX(user_id)) as users,
    SUM(messages) as messages
    from
      (SELECT ceil(@rownum:= @rownum+1/745 ) AS group_id,@slno:= @slno+1 
      as rownum,user_id,messages
      FROM users, (SELECT @rownum:=0)k,(select @slno:=0) r
      order by user_id)a
      group by group_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that stores messages from one user to another. messages(user_id,friend_id,message,created_date). My
I have table messages | id | user_id | recepient_id | message | 1
I have a simple table maintaining messages between users. The table structure looks like
okay, i'm setting up a multi-user chat system. i have a messages table, that
I have Messages and User models with corresponding tables. The Messages table has such
I have a grouped table view that contains 3 sections and each row per
I have an Oracle table which contains event log messages for an application. We
Let's say I have a table called messages with the columns: id | from_id
i have a stack of messages in database table. i want to send these
I have a Message table and a User table. Both are in separate databases.

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.