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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:29:43+00:00 2026-06-08T08:29:43+00:00

I am new to MySQL and I need your help. I have a table

  • 0

I am new to MySQL and I need your help. I have a table with similar data

---------------------------------------------------
|RobotPosX|RobotPosY|RobotPosDir|RobotShortestPath|
---------------------------------------------------
|0.1      |   0.2   |      15   |       1456      |
|0.2      |   0.3   |      30   |       1456      |
|0.54     |   0.67  |      15   |       1456      |
|0.68     |   0.98  |      22   |       1234      |
|0.36     |   0.65  |      45   |       1234      |
|0.65     |   0.57  |      68   |       1456      |
|0.65     |   0.57  |      68   |       2556      |
|0.79     |   0.86  |      90   |       1456      |                 
---------------------------------------------------

As you can see there are repeated values in the column RobotShortestPath, But they are important. Each number represent a specific task. If the number repeats consecutively(ex: 1456), it means that Robot is performing that task, and when the number changes(ex: 1234) it means that it has switched to another task. And if the previous number(ex:1456) appears again it also means that robot is performing a new task(1456) after done with earlier task(1234).

So where I am stuck is I am unable to get no of tasks performed. I have used several things from my minimum knowledge like COUNT, GROUP BY but nothing seem to work.

Here the no.of tasks performed are 5 actually, but whatever I do I get only 3 as result.

  • 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-08T08:29:45+00:00Added an answer on June 8, 2026 at 8:29 am
    SET @last_task = 0;
    SELECT SUM(new_task) AS tasks_performed
    FROM (
      SELECT 
        IF(@last_task = RobotShortestPath, 0, 1) AS new_task,
        @last_task := RobotShortestPath
      FROM table
      ORDER BY ??
    ) AS tmp
    

    Update for multiple tables
    From a database strcture normailization view, your better of with one table, and have a filed identifing what column is what robot, if that not posible for some reason, you can get that by union the tables:

    SET @last_task = 0;
    SELECT robot_id, SUM(new_task) AS tasks_performed
    FROM (
      SELECT 
        IF(@last_task = RobotShortestPath, 0, 1) AS new_task,
        @last_task := RobotShortestPath
      FROM (
        SELECT 1 AS robot_id, robot_log_1.* FROM robot_log_1
        UNION SELECT 2, robot_log_2.* FROM robot_log_2
        UNION SELECT 3, robot_log_3.* FROM robot_log_3
        UNION SELECT 4, robot_log_4.* FROM robot_log_4
        UNION SELECT 5, robot_log_5.* FROM robot_log_5
      ) as robot_log
      ORDER BY robot_id, robot_log_id
    ) AS robot_log_history
    GROUP BY robot_id
    ORDER BY tasks_performed DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

need your help. I tried myself but cant solve it. I have a table
Im new to MySql, and I need to insert into table 10000 random 2-digit
I'm new to MySQL so I really need some help with an issue I'm
In MySQL, I need to create a new table called users with the following
I'm new to bash scripting so would need your help. I am trying to
I need your help to solve a silly problem. I have 2 tables in
I need your help. I have tables using PHP while looping and I need
i need again your help... I have this php code: <? if(isset($_POST['addnews'])){ $type =
Can we create a new MySQL database( not a table, I want a new
[...] public DataSet ReturnPromoMagazinesDs() { MySql.Data.MySqlClient.MySqlConnection mysqlConnection = new MySql.Data.MySqlClient.MySqlConnection(this.connectionString); MySql.Data.MySqlClient.MySqlCommand mysqlCommand = new

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.