Is there a way to access the first and last data of duplicate data in mysql?

Asked 2 years ago, Updated 2 years ago, 32 views

For example, if today's route is stored in DB,

I want to print out a list of today's travel routes. What I want to do here is not print out all the travel routes, but if it's the same place for hours (overlapping data), I want to print out only the first record (and the last record value), so please advise me what to do with the query.

mysql

2022-09-22 20:07

1 Answers

It's not an example of leaving the first and the last, but for example, leaving only the first, you have to create a temporary table.Source

CREATE TEMPORARY TABLE duplicates (id int primary key)

INSERT INTO duplicates (id)
    SELECT t1.id
      FROM table t1
      join table t2 on t2.id = t1.id + 1
     WHERE t1.location = t2.location

This creates a table called duplicates, and then erases the contents in the duplicates from the original table.

What you're trying to do now is you're trying to determine the same position, and you're going to need to calculate the distance because it's not going to be the same position. Then you have to use an expression that calculates the distance with the longitude of the stomach, which requires a separate method implementation. So I recommend you just take care of it on the server.

Or when you first raise the value from the cla to the DB, you can just decide that it's the same location (within 00m distance) and put the value differently if it's the same location.


2022-09-22 20:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.