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

118
Views
Encuentre el valor dentro de una columna que primero no se encuentra

Tengo que escribir un SQL donde tengo que escribir SQL para calcular el RunID primero que no se ve. dejame explicarte con un ejemplo

Ex:

 RunID | RunDate | ErrorID ----- | ---------- | --------- 101 | 04/11/2017 | 1 101 | 04/11/2017 | 2 101 | 04/11/2017 | 3 102 | 04/22/2017 | 2 102 | 04/22/2017 | 3 103 | 04/26/2017 | 1 104 | 04/27/2017 | 3 105 | 04/28/2017 | 4

En el ejemplo anterior, RunID 101 tiene errores 1,2,3. RunID 102 tiene 2,3. Durante la segunda ejecución, no se encuentra el ErrorID 1. Por lo tanto, RunID primero no visto aquí hasta ahora es 102 Pero ErrorID 1 se encuentra nuevamente en RunID 103 y finalmente ErrorID 1 no se encuentra en RunID 104. La consulta debe dar los RunID como 104 que primero no se encuentran.

He intentado usar algunas funciones de ventana como adelanto y retraso, pero no ayuda.

Estos son los resultados esperados:

Fecha no vista por primera vez para ErrorID: 2

 RunID | RunDate | ErrorID ----- | ---------- | --------- 103 | 04/26/2017 | 2

Porque nunca se vio ErrorID 2 (primera instancia de no visto) después de RunID-102

Fecha no vista por primera vez para ErrorID: 1

 RunID | RunDate | ErrorID ----- | ---------- | --------- 104 | 04/27/2017 | 1

ErrorID 1 nunca se vio después de RunID-104

Fecha no vista por primera vez para ErrorID: 3

 RunID | RunDate | ErrorID ----- | ---------- | --------- 105 | 04/28/2017 | 3

ErrorID 3 nunca se vio después de RunID-105

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

so=> with l as ( with m as ( select distinct max(runid) over(partition by errorid),errorid from so80 ) , a as ( select distinct runid,errorid from so80 ) select distinct min(a.runid) over (partition by m.errorid),m.errorid from m join a on m.max < a.runid ) select s.* from so80 s join l on l.min=s.runid and s.errorid=s.errorid ; runid | rundate | errorid -------+--------------+--------- 104 | 04/27/2017 | 3 103 | 04/26/2017 | 1 105 | 04/28/2017 | 4 (3 rows)
over 4 years ago · Santiago Trujillo Report

0

--Get the last runDate when an errorID was seen with t1 as (select runId,runDate,errorID ,first_value(runDate) over(partition by errorID order by runDate desc rows between unbounded preceding and unbounded following) as last_seen from tablename ) --Get the next runDate based on the previous result ,t2 as (select runid,errorID,runDate ,(select min(runDate) from t1 t11 where t11.runDate>t1.last_seen) as date_first_not_seen from t1 ) --Join it to the original table to get the runID information from that runDate in the previous result (t2) select distinct t.runid,t2.errorid,t.rundate from t2 join tablename t on t.rundate=t2.date_first_not_seen

o

 with t1 as (select runId,runDate,errorID ,first_value(runDate) over(partition by errorID order by runDate desc rows between unbounded preceding and unbounded following) as last_seen from tablename) select distinct t1.errorid ,first_value(t.runDate) over(partition by t1.errorID order by t1.runDate desc rows between unbounded preceding and unbounded following) as rundate ,first_value(t.runID) over(partition by t1.errorID order by t1.runDate desc rows between unbounded preceding and unbounded following) as runid from t1 join tablename t on t.runDate>t1.last_seen

Sample Demo

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!