Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Cómo conservar el último conjunto de datos si hay más de 1 conjunto de datos en un día

tengo una tabla que se actualiza aleatoriamente más de una vez al día. Cada actualización contiene alrededor de 2000 filas. Quiero mantener el último conjunto de datos por día y eliminar las filas más antiguas. Construí un ejemplo:

La tabla "fecha" contiene:

 +-------+-------+---------+---------------------+ | title | hhm | hhm_sum | updated | +-------+-------+---------+---------------------+ | 74142 | 21525 | 5874136 | 2020-06-15 00:00:00 | | 74142 | 5263 | 2145 | 2020-06-22 00:00:00 | | 74142 | 21254 | 21458 | 2020-06-22 04:00:00 | | 74142 | 21458 | 3652 | 2020-06-22 08:00:00 | | 74142 | 2158 | 1257 | 2020-06-20 00:00:00 | +-------+-------+---------+---------------------+

Con: SELECT * FROM test.date WHERE updated > DATE_SUB(DATE(NOW()), INTERVAL 24 HOUR);

Obtengo los conjuntos de datos de las últimas 24 horas:

 +-------+-------+---------+---------------------+ | title | hhm | hhm_sum | updated | +-------+-------+---------+---------------------+ | 74142 | 5263 | 2145 | 2020-06-22 00:00:00 | | 74142 | 21254 | 21458 | 2020-06-22 04:00:00 | | 74142 | 21458 | 3652 | 2020-06-22 08:00:00 | +-------+-------+---------+---------------------+

Quiero eliminar las filas más antiguas el mismo día y mantener las más nuevas. ¿Cómo puedo obtener y manejar este valor?

¿Quizás alguien pueda ayudar?

Muchísimas gracias.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si desea mantener la única fila más nueva, ordene por updated desc y tome la primera fila.

 select * from test_date order by updated desc limit 1

Si puede haber varias filas que tengan la updated más reciente, haga una subconsulta para obtener el max(updated) .

 select * from test_date where updated = ( select max(updated) from test_date )
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!