Cumulative Index

  • Well, I have a problem.

    I am trying to calculate a cumulative index.

    Let me explain the scenario. I need to create an index that accumulated when you earn has to allocate to a new table.

    For example:

    count (distinct

    if (id_ameaca = 1 and

    (RelPreliminarRedeAposECP = 'S' or

    RelPreliminarRedeEntreETCeECP = 'S' or

    RelPreliminarRamalServico = 'S' or

    RelPreliminarRamalExterno = 'S' or

    RelPreliminarValvulaBloqueio = 'S'), IncidenteId))

    / (sum (if (id_segmento_dimensao_ = 2, dimensao_segmento)) + sum (RamaisComgas)) //extensao de rede

    * 1000

  • I'm sorry but it's impossible to understand the requirement here. It's not the language barrier between English and Portuguese, it's the lack of clarity and information. Would you be able to demonstrate what you are trying to do with the aid of tables? It looks like a Running Totals requirement.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • :pinch: business specs with a simple numeric example wouldn't hurt.

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply