you need to recover only one type of phone number

Hello

In the following example query, I need to recover only one phone number. The preference is if available Mobile - mobile phone number if this is house number (Type - H1), work a different number (W1).

I've included the script and the sample output that I get from the SQL

Thanks in advance

Concerning
Sriram
select pp.ph_id
,papf.person_id
,pp.ph_type
,pp.ph_no
,pp.date_from
,pp.date_to
from per_phones                      pp
,per_all_people_f                    papf
,per_contact_relationships           pcr
where papf.person_id = pp.parent_id
and pcr.person_id = papf.person_id
and trunc(sysdate) between trunc(nvl(pcr.date_start, sysdate-1))
and trunc(nvl(pcr.date_end, sysdate+1))
and papf.person_id in (146564, 514)
and pcr.primary_contact_flag  = 'Y'
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and trunc(sysdate) between nvl(pp.date_from, sysdate-1) and nvl(pp.date_to, sysdate+1);
output
PH_ID     PERSON_ID     PH_TYPE     PH_NO     DATE_FROM     DATE_TO
3261     514          H1          987524879     13-Jun-04     
117287     514          M          0403672797     11-May-05     
141997     146564          H1          54789620     15-Feb-06     05-Mar-10
311028     146564          H2          235469          5-Dec-09     
311029     146564          W1          8300054          15-Dec-09     
311108     146564          M          04126872     12-Feb-10

You can also try

 select max(pp.ph_id) keep (dense_rank first order by decode(pp.ph_type, 'M',1,'H1',2, 'W1',3), ph_id,
       pp.person_id,
       max(pp.ph_type) keep (dense_rank first order by decode(pp.ph_type, 'M',1,'H1',2, 'W1',3), ph_type,
       max(pp.ph_no) keep (dense_rank first order by decode(pp.ph_type, 'M',1,'H1',2, 'W1',3), ph_no,
       max(pp.date_from) keep (dense_rank first order by decode(pp.ph_type, 'M',1,'H1',2, 'W1',3), date_from,
       max(pp.date_to) keep (dense_rank first order by decode(pp.ph_type, 'M',1,'H1',2, 'W1',3),date_to
  from per_phones pp, per_all_people_f papf, per_contact_relationships pcr
 where papf.person_id = pp.parent_id and pcr.person_id = papf.person_id
       and trunc (sysdate) between trunc (nvl (pcr.date_start, sysdate - 1)) and trunc (nvl (pcr.date_end, sysdate + 1))
       and papf.person_id in (146564, 514)
       and pcr.primary_contact_flag = 'Y'
       and trunc (sysdate) between papf.effective_start_date and papf.effective_end_date
       and trunc (sysdate) between nvl (pp.date_from, sysdate - 1) and nvl (pp.date_to, sysdate + 1)
group by pp.person_id;

Published by: michaels2 on February 25, 2010 08:50

probably, you want to just group by person_id

Tags: Database

Similar Questions

  • need to get only one line when you use between (date columns)

    Hi all

    create the table SAMPLE_ITEMS

    (ITEM_NO, varchar2 (10))

    Date DELIVERY_DATE,

    Number of QTY_SUM1

    Number of QTY_SUM2

    Number ITEM_QTY,

    Number ORDER_QTY,

    Number ITEM_AMOUNT,

    Number of SALES_AMOUNT

    );

    insert into SAMPLE_ITEMS values ('AAA', ' 28 / 04/2014 ',-88, 0,475,262,-123.45,-1188);

    insert into SAMPLE_ITEMS values ('AAA', ' 28 / 05/2014 ', 0, - 122, 475, 262, - 10.234,-1647);

    insert into SAMPLE_ITEMS values ('AAA', ' 16 / 06/2014. ', 0, 0,475,262,-80.59,-135);

    insert into SAMPLE_ITEMS values ('AAA', 19 December 2014 ', 0, 0,475,262,-42.29,-67.5);

    Setting out with my own query,

    ITEM_NOTRUNC (DELIVERY_DATE)QTY_SUM1QTY_SUM2ITEM_QTYORDER_QTYITEM_AMOUNTSALES_AMOUNT
    AAA28/04/2014-880475262-123.45-1188
    AAA28/05/20140-122475262-10.234-1647
    AAA16/06/201400475262-80.59-135
    AAA19/12/201400475262-42.29-67.5

    Every time I question as code

    Select * from SAMPLE_ITEMS

    where DELIVERY_DATE between April 28, 2014 ' and 19 December 2014 '-> they must pass as a parameter

    I need to get only one line

    AAA-88-122475262-256.564-3037.5

    Database 11.2.0.1.0

    Note; Please do not use MAX for Date and do not want to display Date columns in the result

    Note 1: I want to choose DELIVERY_DATE in select it also and only get a line like above the expected result

    SELECT item_no

    SUM (qty_sum1),

    SUM (qty_sum2),

    SUM (DISTINCT item_qty),

    SUM (DISTINCT order_qty),

    SUM (item_amount),

    SUM (sales_amount)

    OF SAMPLE_ITEMS

    WHERE the DELIVERY_DATE BETWEEN TO_DATE (28 April 2014 ', "dd/mm/yyyy")

    AND TO_DATE (19 December 2014 ', "dd/mm/yyyy")

    GROUP BY item_no;

    I will get

    ITEM_NO Trunc (DELIVERY_DATE) QTY_SUM1 QTY_SUM2 ITEM_QTY    ORDER_QTY TTEM_AMOUNT SALES_AMOUNT        

    AAA             12/19/2014                         -88                 -122                475                262                       -256.564              -3037.5

    OK fine, I want to choose DELIVERY_DATE as if so I'll have all the lines, but I want to only show one as shown above

    Because I do report discoverer in Oracle Apps, without taking the DELIVERY_DATE of the select query, it is not possible to move the date as a parameter

    Can you please help me how to do this?

    Thank you

    Post edited by: Rajesh123 NOTE added in the body of the Message

    Post edited by: added test Rajesh123 messages

    Maybe you want a single line in all cases

    Select si.item_no,

    start_date min (d.start_date),

    min (d.end_date) end_date,

    min (si.qty_sum1) qty_sum1,

    min (si.qty_sum2) qty_sum2,

    min (si.item_qty) item_qty,

    min (si.order_qty) order_qty,

    Sum (si.item_amount) item_amount,

    Sum (if. Sales_Amount) sales_amount

    of (start_date select to_date(:date_from,'dd-MON-yyyy'))

    to_date(:date_to,'dd-mon-yyyy') end_date

    of the double

    ) d

    left outer join

    TR sample_items

    on the si.delivery_date between d.start_date and d.end_date

    Group of item_no

    ITEM_NO START_DATE END_DATE QTY_SUM1 QTY_SUM2 ITEM_QTY ORDER_QTY ITEM_AMOUNT SALES_AMOUNT
    - 01/01/1900 31/12/2000 - - - - - -

    Concerning

    Etbin

  • Only one type can be imported. package. Class resolves in one package

    Hello

    I did a class for the database connection named ConnectionClass.class.

    JSPS in public_html directory works very well with import and the session variables.

    but jsp in public_html/subdirectory is unable to import this class and also unable to access session variables.

    I deploy this class under public_html/WEB-INF/classes/directory.

    and also in a vidyabharti.jar of jar in the directory public_html/WEB-INF/lib file

    I am importing into JSP pages as
    < % @ page import = "vidyabharti. "ConnectionClass, java.sql. *" % >

    but I am getting following error

    An error occurred at line: 6 in the generated java file
    Only one type can be imported. vidyabharti. ConnectionClass resolves in one package

    An error occurred at line: 110 in the jsp file: welcome.jsp
    ConnectionClass cannot be resolved to a type

    109: < %
    110: ConnectionClass cs = null;


    An error occurred at line: 115 in the jsp file: welcome.jsp
    ConnectionClass cannot be resolved to a type
    CS = new ConnectionClass();



    I use Tomcat 5.5.28.

    Please help me.

    Hello

    It's a problem possible whith your distribution of tomcat JDT compiler version.
    You know that jasper is the engine that transform the jsp to classes and to reach this goal using a jdt compiler or the Ant's javac compiler task.

    First check that the JDT compiler class is present in the trace for the exception that you have.
    If this is the case follow the steps in the tomcat documentation in in order to use the compiler to Ant.

    http://Tomcat.Apache.org/Tomcat-5.5-doc/Jasper-HOWTO.html

    Apache Ant, which was used in previous versions of Tomcat, can be used instead of the new compiler instead simply by deleting the common/lib/jasper-compiler-jdt.jar file, and place the last distribution of Ant's ant.jar file in common/lib folder. If you do this, you must also use the "javac" to catalina.sh argument.

    If you check the code of the compilation tomcat context seems you can do the same thing, without removing any file, by setting the parameter of compilation of the JspServlet to a value arbitrary diferent of null value.

    Try this alternative by editing the %TOMCAT_HOME%\conf\web.xml file
    and set the attribute of the compiler as follows

        
            jsp
            org.apache.jasper.servlet.JspServlet
            
                fork
                false
            
            
                xpoweredBy
                false
            
            
                compiler
                Ant
            
            3
        
    

    If it works for your problem, we can check the jdt code and maybe make a correction.

    Best reggards,

  • Trying to cancel my subscription but can continue to will return to bike and returns through the cancellation process - tells me I need to call customer service but no phone number is available.

    Trying to cancel my subscription but can continue to will return to bike and returns through the cancellation process - tells me I need to call customer service but no phone number is available.

    Hello Marilyn,.

    Please sign in to your Adobe account and then go to the link below:

    Contact the customer service

    Reference: cancel your creative cloud membership

    Kind regards

    Sheena

  • How do you apply Blur to only one of the two duplicate layers?

    Hello everyone

    I have two layers of dynamic object to a panoramic photo, which is a duplicate of the other and returned vertically.

    I would like to apply Blur to the inverted layer, so this step appears as a reflection of the other layer.

    However, when I apply the blur to the image reversed in its .psb document window, the blur effect ends on the two layers.

    Why the blur apply to two separate smart objects and how could possibly apply Blur to only one of the two double layers?

    Please advise me.

    Thanks as always,

    EAD

    Even if you see two separate layers, Photoshop is not to see them in the same way. When you using duplicated layer (Ctrl/Cmd + J) command, which tells Photoshop to create clones SO double layer sets SO. Update content on one of the 2 cloned layers will take into account changes to another. As you modify the content of a layer of cloned SO that change is automatically reflected in the other. As noted above, the solution is mentioned to apply the blur as a dynamic filter without changing the content (do not double click on layer SO): with SO layer selected in the layers panel, go to filter > blur > Gaussian blur.

    To cite only in case you need this option: you can duplicate the layer SO without cloning to help: command of new dynamic through copy object . In this case you can apply changes to the .psb file you make and modifications will not reflect to another (parent) layer of SO. In this case, disadvantage is that you can't quickly Exchange content on the two SO layers when creating clones SO you can overlay.

  • How can you make boxes select only one?

    I work on the lock to a registration form. There are a few sections with several check boxes, but only one can be marked. We will not accept the form even if there is more than one option marked. Most of the sections there are two boxes, check a box, but not the other. There is a section that has 16 boxes, and Yes only can be marked.  Can I do this?

    Similarly, I also do the same with two text fields, one must be filled.

    Thank you!

    It's easy with checkboxes: give them the same name but different export

    values.

    Not that easy with text fields. You will need to understand how you want

    to work. Other fields must be locked when a field is filled, and

    then unblocked when it's still once empty? They are all would remain editable,

    But if you meet one of them others reset?

    All this must be done with scripts.

  • BlackBerry Z10 check what type of phone number an SMS is sent to

    It doesn't seem to be any way to check which number an SMS has been sent to. Is this fair?  Does that take back me to the entrance, where I can have more than one option by phone.  Seems strange.

    It's true, and I hope that BlackBerry is aware and will be fixed.

  • TDMS file creates several tabs data. You want to create only one.

    Hello NOR community,

    I am currently using the DAQ Assistant with my pots of chain record travel over a long time interval (see annex VI). I then use the vi "Write to a file as" to save the data in a file TDMS (see 'Write the file settings' photo attached for all the parameters chosen for the writing of the file). The file is written, however when I open the PDM file, the document creates a tab in Excel for every second of recorded data (please see attachment ""). It seems that the TDMS file is grouping all data every second, and then by creating a new group of data.

    How can I get the file to write all data on a single tab instead of creating multiple? I don't want to concatenate hundreds of tabs in a single great sheet.

    Thank you

    Chris

    You should not use the comment.  I just removed who and everything worked for me.

  • You can print with only one cartridge

    You have to have two cartridges print?

    Hello

    No, all the cartridges (with inks) you must be able to print on almost any printer.

    Kind regards.

  • Select the desire to only one display limited the number of values

    Hi guys,.

    I have a choice of a select on my page I need to display a list of reports. There should be no restriction on the number of reports that can be created, and therefore, there should be no restrictions on the number shown in the choice of a select.

    However, when the choice of a select 25 values in it, no more will appear later. I have to delete the old values for the most recent to be displayed I don't want.

    Is there a way to make the choice hold a selection of more than 25 values?

    Thank you
    -Mark

    Mark,

    Have you gone into the definition of the page and changed the size of the range for the iterator-1?

    John

  • I need my Skype account which has a phone number to work on my game hand

    I am trying to get hand set to ring with every call that is made using my Skype number how ever I sip and a PBX and tried to use my Skype number with my modem how ever the dose does not work only the thing with ring Skype app

    Go into your settings and make sure "Allow calls from anyone" is checked.

  • Need to recover important files blocked hotmail account

    Hotmail now currently blocked due recent spam account.  Unable to remember Moose exact security password.

    You need to recover files important hotmail account blocked. Security Hotmail may transfer into the new account. Thank you

    Hello

    Answers is a peer group supported and unfortunately has no real influence on Hotmail.

    HotMail has its own Forums, so you can ask your questions there.

    Windows Live Solution Center - HotMail - HotMail Forums Solutions
    http://windowslivehelp.com/

    Hotmail - Forums
    http://windowslivehelp.com/forums.aspx?ProductID=1

    Hotmail - Solutions
    http://windowslivehelp.com/solutions.aspx?ProductID=1

    How to contact Windows Live Hotmail Support
    http://email.about.com/od/hotmailtips/Qt/et_hotmail_supp.htm

    Windows Live Hotmail Top issues and Support information
    http://support.Microsoft.com/kb/316659/en-us

    Error message "your account has been locked" when trying to connect
    http://windowslivehelp.com/thread.aspx?ThreadId=77be7d82-a0e9-49c7-b46d-040ec654a9e2

    Compromised account - access unauthorized account - how to recover your account
    http://windowslivehelp.com/solution.aspx?SolutionID=6ea0c7b3-1473-4176-b03f-145b951dcb41

    Hotmail hacked? Take these steps
    http://blogs.msdn.com/b/securitytipstalk/archive/2010/07/07/Hotmail-hacked-take-these-steps.aspx

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle="" -="" mark="" twain="" said="" it="">

  • You need to know: should I try again Win10 frm Win7 again: is auto repair mode set loop start?

    Hello

    I really dig Win10 until the endless auto start looping of the repair mode.

    I would really like to know is Win10 ready or I re - will the mode of automatic endless repair loop if I re - install.

    TIA,

    MsPositive

    I wait a while before trying again, because it is a free upgrade for one year from July 29, 2015 and wait about 3 to 6 months then try as I'm sure you're not the only one and that it should have a number of bugs from December to March 2016 time period.

    Also create a backup of Windows 7 Image before you start the upgrade process. If something goes wrong, it will be another path to Windows 7 if the Roll Back option (restore Windows 7) doesn't work.

    J W Stuart: http://www.pagestart.com

  • I think I need files .pfm for Adobe Type Basics, based on what I read here.

    I'm trying to install Adobe Type Basics on a 32-bit Windows 7 computer, and I understand that Windows 7, without the program Adobe Type Manager, .pfm files are not created "on the fly".

    Do you need information of the self, for example serial number?

    Hello. Please write to [email protected]>, include your serial number and any other relevant information, and we will try to help.

    Thank you and best regards,

    Christopher

  • BlackBerry Q10 disable the keyboard sounds when you enter the phone number

    I was able to turn off all the sounds of keyboard except one: enter a phone number.

    Does anyone know how to disable these sounds too? I encounter this problem together with the composition screen and the keyboard.

    Thank you!

    You can do the following:

    Settings > Notifications

    Sure, active profile is Normal

    Under profile Cap, tap Normal

    On the normal profile, pass the sound (cursor left)

    Tap customize App Notifications

    Tap phone and set a sound (slider)

    With that, you will hear the ringtone, but you will not hear the dial pad.

    If you have other applications that should its notifications, for example calendar, you must go to customize the Notifications App > calendar and adjust the sound works just as well.

Maybe you are looking for