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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:02:12+00:00 2026-06-09T03:02:12+00:00

below is data table : /* TableName:Data */ id | speed —————- 1 |

  • 0

below is data table :

/* TableName:Data */
  id  |  speed
----------------
   1  |   3
   2  |   0
   3  |   0
   4  |   5
   5  |   6
   6  |   7
   7  |   0
   8  |   0
   9  |   0
  10  |   3
   N  |   2

I want to have a result (with out repeat zero speed) , and specify state of moving ; example :

if first speed row is zero Remove it from result else show with state=START/MOVE
if speed is zero on first row after move state then set state=STOP
if speed is repeat with zero value Remove it from result
after zero value of speed if speed not zero then set state=START

Example Results:

      /* Results */
  id  |  speed  | status
-------------------------
   1  |   3     |  START/MOVE
   2  |   0     |  STOP
   4  |   5     |  START
   5  |   6     |  MOVE
   6  |   7     |  MOVE
   7  |   0     |  STOP
  10  |   3     |  START
   N  |   2     |  MOVE
  • 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-09T03:02:14+00:00Added an answer on June 9, 2026 at 3:02 am
    SELECT     a.*, 
               CASE WHEN @val IS NULL THEN @val:='START/MOVE'
                    WHEN speed = 0 AND @val IN ('START/MOVE', 'START', 'MOVE') THEN @val:='STOP'
                    WHEN speed > 0 AND @val = 'STOP' THEN @val:='START'
                    WHEN speed > 0 AND @val IN ('START', 'MOVE') THEN @val:='MOVE'
               END AS status
    FROM       (
               SELECT    a.*
               FROM      data a 
               LEFT JOIN (
                         SELECT MIN(id)-1 AS id, 0 AS speed
                         FROM   data 
    
                         UNION ALL
    
                         SELECT id, speed
                         FROM   data 
                         ) b ON a.id = b.id + 1 AND (a.speed,b.speed) IN ((0,0))
               WHERE     b.id IS NULL
               ) a
    CROSS JOIN (SELECT @val:=NULL) val_init
    

    Tested and working.

    I’d show a SQLFiddle Demo, but unfortunately, their site is down at the moment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do have a table data as shown below: <td> <label for=title>Title : </label>
I have a piece of matlab code below which reads data from a table.
I have a table that has data like below(sorted by date) COL_A | COL_B
I have a table part with a few demo data as below in Oracle
I have created a Vector object to store data in Table object as Vector<Table>
So I have a class that creates a table to be populated with data.
I have a many-to-many relation with a linked table. See (simplified) schema below. Created
I have putting such data into LinearView. as like below code: public void showResult()
I have a GridView using LinqDataSource to populate data from table Tickets . The
UPDATE : sorry for the confusion. table was not my actual tablename, I have

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.