AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / user-285217

D H's questions

Martin Hope
D H
Asked: 2024-01-19 03:38:36 +0800 CST

Precisa de ajuda com atualização condicional de uma linha de tabela grande (50 milhões)

  • 6

Meu procedimento é o seguinte:

    
set [tb1].[SLD_VAR] =               case when [CalendarDate] = [tb1].[FileDate] and ([tb2].[SLD] - [tb2].[LAG_SLD])/([tb2].[SLD]+1) >= 0.15     then 1 else 0 end, 
    [tb1].[StartingDate_VAR] =      case when [CalendarDate] = [tb1].[FileDate] and [tb2].[StartingDate] <> [tb2].[LAG_StartingDate]            then 1 else 0 end,
    [tb1].[ClosingDate_VAR] =       case when [CalendarDate] = [tb1].[FileDate] and [tb2].[ClosingDate] <> [tb2].[LAG_ClosingDate]              then 1 else 0 end,
    [tb1].[CurrentStatus_VAR] =     case when [CalendarDate] = [tb1].[FileDate] and [tb2].[CurrentStatus] <> [tb2].[LAG_CurrentStatus]          then 1 else 0 end,
    [tb1].[Rate_VAR] =              case when [CalendarDate] = [tb1].[FileDate] and [tb2].[Rate] <> [tb2].[LAG_Rate]                            then 1 else 0 end,
    [tb1].[COF_VAR] =               case when [CalendarDate] = [tb1].[FileDate] and [tb2].[COF] <> [tb2].[LAG_COF]                              then 1 else 0 end,
    [tb1].[Term_VAR] =              case when [CalendarDate] = [tb1].[FileDate] and [tb2].[Term] <> [tb2].[LAG_Term]                            then 1 else 0 end,
    [tb1].[Term_GT_VAR] =           case when [CalendarDate] = [tb1].[FileDate] and [tb2].[Term_GT] <> [tb2].[LAG_Term_GT]                      then 1 else 0 end

from [DataTable]     as [tb1]

left join (
    
    select       [Filedate]
                ,cast([Deal] as inT) as [Deal]
                ,[SLD]
                ,[CurrentStatus]
                ,[StartingDate]
                ,[ClosingDate]
                ,[Rate]
                ,[COF]
                ,[Term],
                DATEDIFF(dd,[ApplicationDate],[ClosingDate])                                                       as [Term_GT],
                LAG([StartingDate],1)                               over (partition BY [Deal] order by [FileDate]) as [LAG_StartingDate],
                LAG([ClosingDate],1)                                over (partition BY [Deal] order by [FileDate]) as [LAG_ClosingDate],
                LAG([CurrentStatus],1)                              over (partition BY [Deal] order by [FileDate]) as [LAG_CurrentStatus],
                LAG([Rate],1)                                       over (partition BY [Deal] order by [FileDate]) as [LAG_Rate],
                LAG([COF],1)                                        over (partition BY [Deal] order by [FileDate]) as [LAG_COF],
                LAG([SLD],1)                                        over (partition BY [Deal] order by [FileDate]) as [LAG_SLD],
                LAG([Term],1)                                       over (partition BY [Deal] order by [FileDate]) as [LAG_Term],
                LAG(DATEDIFF(dd,[ApplicationDate],[ClosingDate]),1) over (partition BY [Deal] order by [FileDate]) as [LAG_Term_GT]

    from        [DataTable]
                    
    where       [FileDate] >= DATEADD( day, -14, @Date)
    
    )  as [tb2]

on          [tb1].[Filedate]        = [tb2].[Filedate] 
and         [tb1].[Deal]            = [tb2].[Deal]

where       [tb1].[CalendarDate]    >= @DateProd

end 

Tendo CalendarDatee Dealjuntos como PrimaryKey, criei alguns índices mas ainda demorou bastante para executar e preciso executar esse procedimento semanalmente. Por favor me ajude com alguma estratégia para otimizar isso.

sql-server
  • 1 respostas
  • 33 Views

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    conectar ao servidor PostgreSQL: FATAL: nenhuma entrada pg_hba.conf para o host

    • 12 respostas
  • Marko Smith

    Como fazer a saída do sqlplus aparecer em uma linha?

    • 3 respostas
  • Marko Smith

    Selecione qual tem data máxima ou data mais recente

    • 3 respostas
  • Marko Smith

    Como faço para listar todos os esquemas no PostgreSQL?

    • 4 respostas
  • Marko Smith

    Listar todas as colunas de uma tabela especificada

    • 5 respostas
  • Marko Smith

    Como usar o sqlplus para se conectar a um banco de dados Oracle localizado em outro host sem modificar meu próprio tnsnames.ora

    • 4 respostas
  • Marko Smith

    Como você mysqldump tabela (s) específica (s)?

    • 4 respostas
  • Marko Smith

    Listar os privilégios do banco de dados usando o psql

    • 10 respostas
  • Marko Smith

    Como inserir valores em uma tabela de uma consulta de seleção no PostgreSQL?

    • 4 respostas
  • Marko Smith

    Como faço para listar todos os bancos de dados e tabelas usando o psql?

    • 7 respostas
  • Martin Hope
    Jin conectar ao servidor PostgreSQL: FATAL: nenhuma entrada pg_hba.conf para o host 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane Como faço para listar todos os esquemas no PostgreSQL? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh Por que o log de transações continua crescendo ou fica sem espaço? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland Listar todas as colunas de uma tabela especificada 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney O MySQL pode realizar consultas razoavelmente em bilhões de linhas? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx Como posso monitorar o andamento de uma importação de um arquivo .sql grande? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison Como você mysqldump tabela (s) específica (s)? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas Como posso cronometrar consultas SQL usando psql? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas Como inserir valores em uma tabela de uma consulta de seleção no PostgreSQL? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas Como faço para listar todos os bancos de dados e tabelas usando o psql? 2011-02-18 00:45:49 +0800 CST

Hot tag

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve