Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda