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 7169497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:00:03+00:00 2026-05-28T15:00:03+00:00

How I can to group continuous data in MySQL table and store its number

  • 0

How I can to group continuous data in MySQL table and store its number to an extra column?

For example:

id, n

1   10
2   10
3   10
4   56
5   10
6   10
7   80
8   12

I want to get something like this. Notice that n of 10 is listed twice.

id   n   cnt
 1   10   3
 4   56   1
 5   10   2
 7   80   1
 8   12   1

Is that any way to do this without FUNCTION?

  • 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-05-28T15:00:05+00:00Added an answer on May 28, 2026 at 3:00 pm

    You can with use of MySQL Variables

    select
          min( PreQuery.ID ) as StartIDOfGroup,
          PreQuery.n,
          count(*) as Cnt
       from
          ( select yt.id,
                   yt.n,
                   @CommonGroup := @CommonGroup + if( @LastNValue = yt.n, 0, 1 ) as Common,
                   @LastNValue := yt.n as JustAPlaceholder
               from
                  YourTable yt,
                  ( select @CommonGroup := 0, @LastNValue := 0 ) SQLVars ) PreQuery
       group by
          PreQuery.n,
          PreQuery.Common
       order by
          StartIDOfGroup
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there someway we can group similar data in java? i want to group
Is there any jQuery plugin that can group data - either list or table
How can I using group by with union in T-SQL? I want to group
In MSBuild you can data drive target dependencies by passing a item group into
Given I have data like the following, how can I select and group by
How can I return what would effectively be a contiguous GROUP BY in MySQL.
I can group by seconds or minutes with something like the following: SELECT datepart(minute,
Foo.group(:start_at).count(:id) How I can group this by date ? the start_at column is an
Trying to work with groupby so that I can group together files that were
I have a Python regular expression that contains a group which can occur zero

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.