De-duping customers based on a second field

Not sure what to call this, but say I have a table that has two fields: Customer ID and Movie Purchased (so customers are not unique in the table):
CUST ID ....... MOVIE
====== ....... =====
1 ....... Dark Knight
1 ....... Swing Vote
2 ....... Pineapple Express
2 ....... Swing Vote
3 ....... The Mummy
3 ....... Mamma Mia
etc.
I'd like to write a query that returns a distinct customer ID and the movie purchased based on a hierarchy. So, if the hierarchy goes 1-Dark Knight, 2-Swing Vote, 3-Pineapple Express, I want the customer ID and that movie name if they purchased it. In this example I'd like to return :
CUST ID ....... MOVIE
====== ....... =====
1 ....... Dark Knight
2 ....... Swing Vote
(no cust ID 3 because their movies weren't in the hierarchy)
Any hints as to the best way to do this? I originally thought a CASE statement might somehow only retrieve the cust ID once but that does not seem to work. Any thoughts would be appreciated.
Thanks!

I think I'm interpreting what you wanted differently than isotope, heres my interpretation with an extra record to help illustrate the difference in my thought process.
Attempt 1 - Still Playing with Analytic Functions so not sure if this will break easily
with hierarchy as (
      select 1 as rank, 'Dark Knight' as movie from dual union all
      select 2, 'Swing Vote'        from dual union all
      select 3, 'Pineapple Express' from dual),
    table1 as (
      select 1 as cust_id, 'Dark Knight' as movie from dual union all
      select 1, 'Swing Vote' from dual union all
      select 2, 'Pineapple Express' from dual union all
      select 2, 'Swing Vote' from dual union all
     select 3, 'The Mummy' from dual union all
     select 3, 'Mamma Mia' from dual union all
     select 4, 'Pineapple Express' from dual union all
     select 4, 'Dark Knight' from dual)
   select distinct t.cust_id, FIRST_VALUE( t.movie) OVER (PARTITION BY t.cust_id ORDER BY h.rank)
   from table1 t inner join hierarchy h on t.movie = h.movieAttempt 2
with hierarchy as (
      select 1 as rank, 'Dark Knight' as movie from dual union all
      select 2, 'Swing Vote'        from dual union all
      select 3, 'Pineapple Express' from dual),
    table1 as (
      select 1 as cust_id, 'Dark Knight' as movie from dual union all
      select 1, 'Swing Vote' from dual union all
      select 2, 'Pineapple Express' from dual union all
      select 2, 'Swing Vote' from dual union all
     select 3, 'The Mummy' from dual union all
     select 3, 'Mamma Mia' from dual union all
     select 4, 'Pineapple Express' from dual union all
     select 4, 'Dark Knight' from dual)
   select t.cust_id, t.movie
   from table1 t inner join hierarchy h on t.movie = h.movie
   where h.rank = (select min(rank) from table1 t1 inner join hierarchy h1 on t1.movie = h1.movie where t1.cust_id = t.cust_id)Both result in identical output of
1     Dark Knight
2     Swing Vote
4     Dark KnightI interpreted this slightly different than isotope in thinking that you were going to have an overall hierarchy not one per customer which I think is how isotope took it as he used intersect to match them up. Oh well either way maybe it will be useful to someone!
Rich
Message was edited by:
BengalGuy

Similar Messages

  • CRM 7.0 WebUI:  Second field searchhelp based on first field value

    Hi,
    I created an all-custom search/result component, all other things are working correctly, except one - on result list, when in change mode, the second field should have a dropdown list which is filled based on the first field value, user can pick one.  I searched this forum and SAP docs, so far I haven't found a solution.  Has anyone done this?  or have you seen any SAP standard screens having this kind of function?
    Thanks.
    Steven
    Edited by: Steven Lee on Apr 23, 2010 11:11 AM
    Edited by: Steven Lee on Apr 23, 2010 11:11 AM

    Hi Steven,
    1. Declare a Global Drop Down table as an attribute in your implementation class.
    2. Create an Event when you select a drop down value for the first field.
    3. In this event handler, build the global drop down table.
    4. In the get_v method of your second field, fill the returning parameter of dropdown values from the values in your global dropdown table you just filled in the Event Handler method.
    I have used this successfully. I hope it works for you too.
    Please let me know if you have questions.
    Thanks
    Vishal

  • CRM 7.0 WebUI:  Dropdown for second field is based on first field value

    Hi,
    I created an all-custom search/result component, now having one challenge - requirement is - on result list, when in change mode, the second field should have a dropdown list which is filled based on the first field value, where user can pick one.  I searched this forum and SAP docs, so far I haven't found a solution. Has anyone done this? or have you seen any SAP standard screens having this kind of function?
    Thanks.
    Steven

    Hi Steven,
    You will rarely see a result list component in change mode.
    Anyhow, to fulfill your requirement, you have to trigger a round trip for the first field when a value is selected.
    You can do this by specifying a dummy event in GET_P method.
    The GET_V method of the second field will trigger for this round trip and you can trigger the values.
    Regards,
    Masood Imrani S.

  • Question on populating a field based on 2 other fields

    Hi,
    I am looking for a solution wherein I need to populate a field (say no of days) based on the other two fields selected by the user (say date from and date to). As soon as user selects the value on "date to" field, "no of days" field should be auto-populated as the value from "date to - date from". I have tried using setter and getter methods on all three field, set valuechangelistener on date to field, set auto submit to true and in the valuechangelistener event code, I am doing the calculations as mentioned in the below snippet.
    public void onChangeDateTo(ValueChangeEvent evt){
    this.dtDateTo= (java.util.Date)evt.getNewValue();
    this.dtDateFrom = (java.util.Date)getDateFrom();//This is the getter method for date from field
    System.out.println("onChangeDateTo "+ this.dtDateFrom+":"+this.dtDateTo);
    if (evt.getNewValue() != null){
    int intCalcNoOfDays = DateHelper.getBusinessDaysCount(this.getDateFrom(),this.getDateTo()) + 1;// my custom class which does the calculation
    String strCalcNoOfDays = String.valueOf(intCalcNoOfDays);
    System.out.println("strCalcNoOfDays "+strCalcNoOfDays);
    this.setNoOfDays(strCalcNoOfDays);
    I am getting NullPointerException while getting the value for date from (this.dtDateFrom). I have tried other approaches like attaching a binding to date from field, passing attributes etc but no luck. Can someone assist me in achieving this? Basically I need to populate one field automatically based on values entered on two other fields whenever tab event/user selects value on second field AND it shouldn't fire any other validations on the form (basically partial trigger).
    Thanks very much for the help in advance.
    Thanks
    Shree

    Thanks Lilly.
    I don't have a backing bean associated with the page. I have managed bean instead. JSF source code snippet below
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich" xmlns:h="http://java.sun.com/jsf/html">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
    <af:document title="LMS" id="d1">
    <af:messages id="m1"/>
    <af:form id="f1">
    <af:panelStretchLayout id="psl1" startWidth="160px">
    <f:facet name="top">
    <af:panelGroupLayout id="pgl1" layout="vertical" halign="center">
    <af:panelFormLayout id="pfl1" rows="1" maxColumns="1">
    <af:outputText value="LMS" id="ot1"
    inlineStyle="color:Blue; font-family:'Times New Roman', 'Arial Black', times, Serif; font-size:175%; font-weight:bold; text-align:center;"/>
    </af:panelFormLayout>
    </af:panelGroupLayout>
    </f:facet>
    <f:facet name="bottom">
    <af:panelGroupLayout id="pgl2"/>
    </f:facet>
    <f:facet name="center">
    <af:panelGroupLayout layout="scroll" id="pgl4">
    <af:outputText value="Dashboard" id="ot6"
    inlineStyle="color:Green; font-size:150%; font-family:'Times New Roman', 'Arial Black', times, Serif; font-weight:bold; text-align:center;"
    visible='#{clickActionHandlerBean.clickLink== "HOME"}'/>
    <af:spacer width="10" height="10" id="s1"
    visible='#{clickActionHandlerBean.clickLink== "HOME"}'/>
    <af:spacer width="10" height="25" id="s5"
    visible='#{clickActionHandlerBean.clickLink=="APPLY"}'/>
    <af:panelFormLayout id="pfl2" rows="1" maxColumns="1"
    visible='#{clickActionHandlerBean.clickLink=="APPLY"}'>
    <af:selectOneChoice label="Type" id="soc1" showRequired="true"
    immediate="true" value="#{bean1.type}">
    <af:selectItem label="X1" value="X1" id="si1"/>
    <af:selectItem label="X2" value="X2 id="si2"/>
    <af:selectItem label="X3" value="X3" id="si3"/>
    <af:selectItem label="X4 value="X4" id="si4"/>
    </af:selectOneChoice>
    </af:panelFormLayout>
    <af:panelFormLayout id="pfl3" rows="1" maxColumns="3"
    visible='#{clickActionHandlerBean.clickLink=="APPLY"}'>
    <af:inputDate label=" Date From" id="id1"
    rendered='true'
    showRequired="true" inlineStyle="vertical-align:baseline;"
    value="#{bean1.dateFrom}">
    <af:convertDateTime pattern="dd-MMM-yyyy" secondaryPattern="MM/dd/yyyy"/>
    </af:inputDate>
    <af:inputDate label="Date To" id="id2"
    rendered='true'
    showRequired="true" value="#{bean1.dateTo}" partialTriggers="it1"
    valueChangeListener="#{bean1.onChangeDateTo}"
    autoSubmit="true">
    <af:convertDateTime pattern="dd-MMM-yyyy" secondaryPattern="MM/dd/yyyy"/>
    </af:inputDate>
    <af:inputText label="No of Days" id="it1" columns="7" showRequired="true"
    rendered="true" value="#{bean1.noOfDays}" maximumLength="2">
    <af:validateRegExp pattern="[0-9]{1,10}"
    messageDetailNoMatch="No of days can have only numbers"/>
    </af:inputText>
    </af:panelFormLayout>
    <af:spacer width="10" height="50" id="s6"/>
    <af:group id="g1">
    <af:spacer width="250" height="10" id="s7"
    visible='#{clickActionHandlerBean.clickLink=="APPLY"}'/>
    <af:commandButton text="Save" id="cb1" partialSubmit="true" blocking="false"
    immediate="false"
    visible='#{clickActionHandlerBean.clickLink=="APPLY"}'
    actionListener="#{bean1.ApplyButtonClicked}">
    </af:commandButton>
    <af:spacer width="20" height="10" id="s8"/>
    <af:commandButton text="Cancel" id="cb2"
    visible='#{clickActionHandlerBean.clickLink=="APPLY"}'/>
    </af:group>
    </af:panelGroupLayout>
    </f:facet>
    <f:facet name="start">
    <af:panelGroupLayout id="pgl3" halign="left">
    <p>
    <af:outputText value="#{userinfo.userInfo.firstName}" id="otWel"
    inlineStyle="color:Maroon;" rendered="false"/>
    </p>
    <af:spacer width="1" height="50" id="s2"/>
    <p>
    <af:commandLink text="Home" id="glHome" action="#{clickActionHandlerBean.showHomeRN}"/>
    </p>
    <p>
    <af:commandLink text="Apply" id="glApply"
    action="#{clickActionHandlerBean.showApplyRN}"/>
    </p>
    </af:panelGroupLayout>
    </f:facet>
    </af:panelStretchLayout>
    </af:form>
    </af:document>
    </f:view>
    </jsp:root>
    Thanks
    Shree

  • Workflow based on created date field in opportunity?

    Hi All,
    Can we write a workflow based on created date field in opportunity that if a opportunity record has not been modified after say 90 days,what will be the workflow syntax.
    I just want an email notification to owner and owner's manager.
    Thanks in advance,
    Manish.

    I think you can use the WAIT workflow using Duration('P90D') then Send Email, triggering it upon save and upon modification. Make sure that the Re-evaluate Rule Conditions After Wait option is checked so that the previous WAIT would be reset upon modification.
    Edited by: marcocollado on Aug 31, 2012 5:57 AM

  • Sorting records dynamically in REF cursor, based upon a dynamic field

    Hi,
    I have a REF CURSOR built by using row type, table type and PIPELINE function. I have opened the ref cursor now. I would like to update a field called 'RANK' based upon 'RATIO' field in the REF CURSOR. i.e order the records in the ref cursor by RATIO field and then update the RANK as 1, 2, 3, 4, ....
    Aim: I want to update a field in the REF CURSOR based upon another numeric field.
    Please help me.
    OPEN sales FOR
    SELECT RANK, ratio
    FROM TABLE (fngetfundholdingsale (in_primarykey, in_flag));
    loop
    fetch sales into sale1;
    exit when sales%notfound;
    --I want to update sale1.rank based upon ratio
    end loop;
    Thanks
    Ashok

    Try to use NDS (Native Dynamic SQL):
    l_order := 'ratio';
    OPEN sales FOR
    'SELECT rank' ||
    '  FROM TABLE (fngetfundholdingsale (:in_primarykey, :in_flag))' ||
    ' ORDER BY ' || l_order
      USING in_primarykey, in_flag;Regards,
    Zlatko

  • Populate field based on other lookup field in form

    Hello,
    In a list item in Infopath, I have a field which looks up a location. You can select the location in a dropdown list.
    I want to fill another field with the manager name of the selected location. That manager name is a field in the other form also. In a Sharepoint workflow you can do such a thing (look for a specific list item in another list, based on a selected field in
    that list).
    To summarize: if I fill the location field with info from another list, I want to automatically fill another field with the manager of that location - which is also in that other list.

    Hi  mRRRc1,
    For achieving your demand , please take steps in the InfoPath as below:
    Open the list which contains the look up field using InfoPath.
    Create a Data Connections from  SharePoint list:  Click From SharePoint  List  control under tag DATA -> Input your site URL in the Data Connection Wizard page -> Select the original
    list -> Select  Location and Manager field -> Enter a name for this data connection(such as Test) -> Finish.
    Create a Rule for Location look up field :   
    Condition: LocationLookUp  is not blank
    Rule type: Action
    Run these actions: Add “Set a field’s value”
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • How to create dynamic ed flash charts based on user selected fields in Orac

    Hi all,
    Can any of the experts please tellme "how to create dynamic ed flash charts based on user selected fields in Oracle apex".
    Thanks
    Manish

    Hello,
    Lots of different ways to do this, I blogged about one way (using a Pipelined function) here -
    http://jes.blogs.shellprompt.net/2006/05/25/generic-charting-in-application-express/
    Other options include using a PL/SQL function returning the string to use as the dynamic query etc.
    Hope this helps,
    John.
    Blog: http://jes.blogs.shellprompt.net
    Work: http://www.apex-evangelists.com
    Author of Pro Application Express: http://tinyurl.com/3gu7cd
    REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone!

  • Classyfying the customers based on their sales

    Hi,
    I have report showing the cutomers and the sales units to them
    for example:
    customer     sales
    A     200
    B     300
    C     50
    D     100
    how can i grade the customers based on their sales, for example
    Grading                customer     sales
    Gold >=300            B              300
    Sub total                   300
    silver >100 & <300    A              200
    sub total                   200
    Bronze <=100          C               50
                       D              100
    sub total                   150
    Could anyone please help me
    Message was edited by:
            rapo
    Message was edited by:
            rapo

    Thanks ganesh and ramesh,
    Thanks for your inputs.
    By exceptions, i can get classigy them and even color them and sort them but i cannot get the sub totals for each classification.
    Ramesh, can you please clarify in detail how this can be done by using the formula.
    thanks and regards

  • Need Report based on "CUSTOM DATA field @ Shop Order Maintenance"

    Need the REPORT based on CUSTOM DATA field.
    Requirement - I am having the CUSTOM data at Shop Order Maintenance that is called as XXX, I need some report in SAP ME which can display the SFC related to particular Shop order based on XXX Number.

    Hi!
    As far as I remember there is no such base report. So, you may try to create it using SDK or request it as custom enhancement from SAP.
    If you want to create it using SDK, you can find the required data for report in CUSTOM_FIELDS table.
    Regards,
    Alex.

  • MOVE THE SECOND FIELD VALUES

    hi guys,
    I am uploading the data for open AR items from an PIPE delimiter file. I read the data into an internal table and spilit the data at pipe delimiter.... now I have to do some validations.
    There is one trailer record at the end in the file. In that trailer record I get the number of records in the second field like
    9|20|100.000|10.000|        here 20 is the number of records
    if it is a standard structure file then i can write the logic as
    IF V_FNAME1 NE 'X'.
        DESCRIBE TABLE I_FILEDATA1 LINES V_FILEDATA1.
        READ TABLE I_FILEDATA1 INTO WA_FILEDATA1 INDEX  V_FILEDATA1 .
        MOVE WA_FILEDATA1+2(5) TO V_LINES1 .
        IF V_FILEDATA1 NE V_LINES1.
          MESSAGE 'NUMBER OF LINES READ ARE NOT SAME' TYPE 'E'.
        ENDIF.
      ENDIF.
    In the above logic i counted the number of records and compared that number with the number of records given in the trailer record (20)
    how to modify this logic if the file is a pipe delimiter file.....
    how to capture that value into one variable can any one guide me please......
    SRI

    Are you planning to do this within the previous READ_FILE_DATA subroutine or outside? Is your trailer record always of the same structure in all the 3 files? If so, you can declare a new structure as follows and insert this code in your subroutine where you upload the file, after the records are appended to itab_file.
    data: begin of wa_trailer,
            rec_type,
            count(10) type n,
            field1(?) type c,
            field2(?) type c.
    data: end of wa_trailer.
    Now in your subroutine, after itab_file is filled up insert this code
    describe table itab_file lines v_rec_count.
    v_rec_count = v_rec_count - 1.
    read table itab_file into wa_trailer index v_rec_count.
    if v_rec_count <> wa_trailer-count.
    error.
    endif.
    Here I am assuming that the count 20 you have is not including the trailer record. If it is also included, then remove the "v_rec_count = v_rec_count - 1." sentence.

  • Tcode to find the fields ,tables based on description of fields

    hi folks,
    tcode to find the fields ,tables based on description of fields,POINTS  will be awarded for the answers ,plz give reply.

    Hello Kumar
    Table DD03T contains the field descriptions.
    Regards
      Uwe

  • XML Forms Builder: Sorting news based on a date field in a XML form

    Hi Experts
    I have a requirement and I am stuck up in finding a solution. I have a XML form and this has been mapped to a folder in KM. It publishes news. In the collection renderer settings there is an option to sort the news ascending or descending based on created/modified criteria.
    The requirement is to sort the news based on a date field in XML form. Can you experts help me in getting the solution for same?
    The users who post the news in our portal needs the information to be sorted based on a date field shown.
    Thank you
    Best regards
    Ramamoorthy D

    Hi Experts
    I have not got any solution for this issue. Can any of you get me some clue to work on this issue with sorting news based on a date field in a XML form?
    I removed the property link from the screen field Input field.
    Thank you
    Best Regards
    Ramamoorthy D

  • User based block the pricing field in the sale order

    HI FRIEND
    We have requirement user based block the pricing field in the sale order
    pls suggest me the configuration steps
    with regards
    dinesh

    hi friend
    when create a sale orde,r price and exchange rate is triigger from the master record.
    head department want not require to End user to change the price in the sale order .
    so head department only have authorisation to change price.
    selected user is not allow the change the price.
    so i need the configuration
    with regards
    dinesh

  • Email customers based on data in a webapp

    Hi all
    A question - Is BC capable of emailing customers based on data in a webapp that was submitted by that customer?
    Thanks

    Like send a different workflow given the choice one makes on a form. If so then yes. You will need to use a little jQuery to make it work right.
    http://helpx.adobe.com/business-catalyst/partner/create-workflow-notification.html#id_2285 7
    Basicly you would set it up so that when you get the data you want you would select the right workflow in the background.
    Or just change the text on the dropdown and let them choose that way.
    <select name="WorkflowList">
    <option value=ID1>Option One</option>
    <option value=ID2>Option Two</option>
    <option value=ID3>Option Three</option>
    </select>
    OR --- I'm way off and you require a different solution?

Maybe you are looking for