get a number of unique values without separating values that belong to the same block of values

后端 未结 6 537
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 15:06

I\'m OK with either a PL/SQL solution or an Access VBA/Excel VBA (though Access VBA is preferred over Excel VBA) one. so, PL/SQL is the first choice, Access VBA is second a

6条回答
  •  甜味超标
    2020-12-19 15:28

    This is not a full answer, but I don't want to write a lot of queries in comments.
    Your main goal is to send information to people, and to avoid the situation when one person receives fax twice. So you first you need a list of unique recipients, like this:

    select distinct otherid
      from NR_PVO_120
    

    If one person has two fax numbers, you need to decide, which one to choose:

    select otherid, fax
      from (select otherid, fax, row_number() over (partition by otherid order by ) rn
              from NR_PVO_120)
     where rn = 1
    

    (All of this you have in answers of previous question)
    If you take this list of fax numbers, all of your recipients receive the fax, and only one fax for every person. But some fax numbers will not be used. You can easily find them:

    select otherid, fax
      from (select otherid, fax, row_number() over (partition by otherid order by ) rn
              from NR_PVO_120)
     where rn > 1
    

    If you send fax to any of this numbers, some of people get one fax twice.
    English is not my native language, so I don't understand what you mean when say "without breaking up fax numbers". As I can see in your question, possibly you need to use order of fax numbers in your question as number priority (the higher number is situated in the table - the higher probability to use it). It seems like you can use following:

    select otherid, fax
      from (select otherid, fax, row_number() over (partition by otherid order by row) rn
              from NR_PVO_120)
     where rn = 1
    

    here row in order by clause is a Row from your example table.

    UPD
    P. S. About my last query: we have a table with certain order, and the order is important. We take rows of the table line by line. Take first row and put its otherid and fax to result table. Then take next row. If it contains another fax number and otherid, we take it, if otherid already in our result table, we skip it. Did you ask this algorithm?

提交回复
热议问题