Different Criteria same field select?

New to straight Oracle SQL, I come from a programming background using MySQL. I’m going to smipify this a lot and changed table and field names and such to protect the identity of the innocent tables...jk
BOOKS has an b_id and b_name =>(book id and name).
1234, Old man and the Sea
2345, War of the Worlds
TRANSACTIONS has b_id, key_code and date.
1234, TT3, 15-Feb-09
1234, A890, 01-jan-09
1234, A456, 11-jan-89
2345, TT3, 5-may-09
1234, Z80, 25-oct-07
2345, Z80, 25-Nov-07
What I need to do is for each book that has a TT3 transaction; find the Z80 transaction and find how many days passed between the two transactions. I could do this so easy in program but I’m not sure how to do in a select. Thanks in advance.

with books as (
               select 1234 b_id,'Old man and the Sea' b_name from dual union all
               select 2345,'War of the Worlds' from dual
       trn as (
               select 1234 b_id,'TT3' key_code,to_date('15-Feb-09','dd-mon-yy') dt from dual union all
               select 1234,'A890',to_date('01-jan-09','dd-mon-yy') from dual union all
               select 1234,'A456',to_date('11-jan-89','dd-mon-yy') from dual union all
               select 2345,'TT3',to_date('5-may-09','dd-mon-yy') from dual union all
               select 1234,'Z80',to_date('25-oct-07','dd-mon-yy') from dual union all
               select 2345,'Z80',to_date('25-Nov-07','dd-mon-yy') from dual
select  distinct b_name,
                 b.b_id,
                 abs(next_dt - dt) days_between_tansactions
  from  (
         select  b_id,
                 key_code,
                 lead(key_code) over(partition by b_id order by dt) next_key_code,
                 dt,
                 lead(dt) over(partition by b_id order by dt) next_dt
           from  trn
           where key_code in ('TT3','Z80')
        ) t,
        books b
  where b.b_id = t.b_id
    and (
            (key_code = 'TT3' and next_key_code = 'Z80')
         or
           (key_code = 'Z80' and next_key_code = 'TT3')
B_NAME                    B_ID DAYS_BETWEEN_TANSACTIONS
Old man and the Sea       1234                      479
War of the Worlds         2345                      527
SQL> SY.

Similar Messages

  • Field selection group

    Dear Friends,
                      Can you please explain howthe field selection group,field reference works in Materials Management.and how this OMS9 screen works with this..
    Thanks&regards
    Eliaz

    Define whether a field is hidden or displayed, or whether an entry is mandatory or optional in material master maintenance by assigning the field to a field selection group in OMSR.
    Each field selection group has a number between 1 and 240.
    The values of the field selection groups have been preassigned as follows:
    001-110  Material master for industry 
    111-120  Reserved for customers (except where the values are already in use) 
    121-150  Material master for industry 
    151-210  Material master for retail 
    211-240  Reserved for customers 
    Create and maintain field references (OMS9).
    All the fields in the same fields group will have the same field selection option.
    (hide, display, required entry, or optional entry) 
    You can see where a field reference is used by choosing Where-used list.
    Define or change the field references as required (except for field references with the prefix SAP which must not be changed). New field references must begin with Y or Z.
    Changing the Field Selection Options for a Field Selection Group
    1. Specify the field selection group .
    2. Select the field selection option (hide, display, required entry, or optional entry) 
        for each field reference as required.
    3. Save.
    Creating a Field Reference
    1. Choose New entries.
    2. Specify a field reference beginning with Y or Z.
    3. Select the field selection option for each field selection group as required.
    4. Save.
    Changing a Field Reference
    1. Double-click the relevant field reference.
    2. Change the field selection option for each field selection group as required.
    3. Save.
    Define industry sectors and industry-sector-specific field selection in OMS3.
    Define plant-specific field selection and screen selection in OMSA.

  • Different fonts in the same field

    Is it possible to format a single field with two different fonts. I have concatenated two database columns to get this field. But I want different fonts for the two columns. I could achieve this by using a format trigger and placing some html tags. But this solution only works if the output is in HTML style sheets. It does not work if I want the output to be in PDF. Does anybody know how to achieve it in PDF? Is it possible at all (from what I have seen it isn't). I will be grateful for any help in this direction.
    Thanks
    Janaki

    Hi!
    Try this:
    Let say you have scott/tiger and emp-table and want to concatenate and print ename and job in the same field but with different fonts.
    1. In the Database model you have the columns seperate as usual.
    2. Create a boileplate text field and put &ENAME &JOB in this field.
    3. Select &ENAME and set the right font to it, set another font for &JOB.
    4. Run and test. This should work...

  • Field selection from differant tables

    hello all,
             i need to select differant fields from differant tables when i select common fields from both the tables, is it necessary that the common field need to be a primary key in both tables.
    thanks in advance
    seenu

    HI,
        No its not required that the common field be part of the primary key in both tables only thing is you need to prefix the table name if the field names are same. But if you are using a INNER JOIN then there is no need to select both fields since you know the content of both fields will be same if JOIN is ON these fileds as well.
    Regards,
    Sesh
    Message was edited by:
            Seshatalpasai Madala

  • Field selection for movement type 601 account 894025 differs for cutomer

    While posting goods after saving delivery merror message
    Field selection for movement type 601/aact 894025 differs for customer goods movement
    I tried OMJJ>Mvtmt Type>601>Field selection enjoy>601  KONTO  Optional field
    Now this is only happening in the cases where I have assigned free goods Inclusive 10MT. If the order is less than 10MT (that is if no free goods attached) posting is accepted & billing & account determination is processed successfully.
    I am unable to identify the reason though I have worked a lot on MM/Fico on the system.
    Please provide your valued inputs why this is happening?
    Thanks for your time.
    Rajiv

    Hi Raja,
    Thanks for prompt reply.
    I shall appreciate if you elaborate how to check
    check the Field selection goup in control tab for that GL 
    I tried OBC$--> (Is this correct?)
    I checked cost center field G004 -->Addl Act assignemtn -->Cost center which is Optional entry. Should I check any other items on the screen as I am unable to understand which field is applicable on a/c field.
    Profit center, cost object are  in G004 as supressed field.
    So should I make optional? So thing will work.
    Other Q should I also consider G025 Inventory adjustment account? As per error this a/c is not shown. So pl advise me steps or heading which I should consider.
    Thanks for yr time.
    Rajiv

  • Providing F4 help for the same field on selection screen

    Hello Experts,
    My requirement is :
    There are 2 radio buttons and a parameter "p_file" on my selection scree.
    1. rb_appl
    2. rb_pres
    If the radio button rb_appl = 'X', I need to place the logic of F4 help of application server for the field p_file. Else if the rb_pres = 'X', then I need to place the logic of F4 help of presentation server for the same field p_file.
    I have written the code in the below manner
    PARAMETERS: rb_appl RADIOBUTTON GROUP rad DEFAULT 'X',
                             rb_pres RADIOBUTTON GROUP rad ,
                             p_file   TYPE ibipparms-path.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      IF rb_appl = 'X'.
          PERFORM f_applictn_server_filenm.
      ELSEIF rb_pres = 'X'.
        PERFORM f_presentation_filenm.
      ENDIF.
    But I am getting the F4 help for only the radio button for which i have placed the default value in the parameters.
    So please let me know how to define the F4 help for the same field based on the radio buttons.

    Hi,
    You can acheive the same by the addition of [USER-COMMAND fcode].
    RADIOBUTTON GROUP group [USER-COMMAND fcode] - The addition USER-COMMAND can be used to assign a function code fcode to the first parameter in a radio button group. The function code fcode must be specified directly, and have a maximum length of 20 characters. When the user selects any radio button of the radio button group on the selection screen, the runtime environment triggers the event AT SELECTION-SCREEN and transfers the function code fcode to the component ucomm of the interface work area sscrfields.
    So you code should be altered as
    PARAMETERS: rb_appl  RADIOBUTTON GROUP rad
                         USER-COMMAND radclick    "Addition which you have to make.
                         DEFAULT 'X',
                rb_pres  RADIOBUTTON GROUP rad ,
                p_file   TYPE ibipparms-path.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      IF rb_appl = 'X'.
        PERFORM f_applictn_server_filenm.
      ELSEIF rb_pres = 'X'.
        PERFORM f_presentation_filenm.
      ENDIF.
    Thanks & Regards,
    Harish

  • Validate same field, same form, different actions

    Hi !
    I have the following problem. I have a single form with one field = sum and two buttons = withdraw and substract. I need to do the followings validations :
    a) sum must be an integer > 0;
    b) is substract is pressed sum < = existing account's value.
    Here are fragments from code :
    bank_operations.jsp
    <html:form action="/operations">          
         Sum (value): <html:text property="sum" />          
         <html:messages id="err_sum" property="sum">
              <bean:write name="err_sum" />
         </html:messages></p>
         <html:submit property="submit">     
              <bean:message key="button.withdraw" />
         </html:submit>
         <html:submit property="submit">     
              <bean:message key="button.substract" />          
         </html:submit><br>     
    </html:form>
    Here is SumForm
    public class SumForm extends ActionForm {
    private String sum;
    setters / getters
    public ActionErrors validate(ActionMapping mapping,
         HttpServletRequest request) {
         ActionErrors errors = new ActionErrors();
         if (!isNumeric(getSum())) {
         errors.add("sum", new ActionMessage("errors.sum.numeric"));
         request.setAttribute("account", account);
         } else {
         if (Integer.parseInt(getSum()) < 0) {
              errors.add("sum", new ActionMessage("errors.sum.numeric"));
              request.setAttribute("account", account);
         return errors;
    Here is the Action file :
    public class SumAction extends LookupDispatchAction { 
    public ActionForward withdraw()...
    public ActionForward substract()...
    Here is the struts-config.xml
    <action
    path="/operations"
    type="struts.action.SumAction"
    name="sumForm"
    scope="session"
    parameter="submit"
    validate="true"
    input="/pages/operations_struts.jsp">
                   <forward name="success" path="/pages/operations_struts.jsp" />
                   <forward name="failure" path="/pages/operations_struts.jsp" />
    </action>
    The problem is : If I know that only in the Action file I know which button was pressed , how can I made two different validation for the same field /same form , but different buttons pressed ? Or can I update validate method from SumForm file from the Action file? (where I can know which buttons was pressed).
    Thank for every your ideea !
    Forgot the details : it's about Struts2 . :)

    Thanks for your reply, but unfortunately I didn't get the idea. Where I should put that line? In the validate method of the form file?
    If this is the case, in page for <html:submit element what should I declare? I saw that something like id or name, I think is not supported by Struts. I'm not sure.
    Thanks again.

  • Select Statement to fetch Multiple records of a same field

    Hi one and all,
               I have ascenario like this,
    I need to fetch the material starting with 'MA%' and material Starting with 'RT%' and so on.....data from the table resb with reference to AFPO-AUFNR.
    Now how can write select Query.
    Iknow how to fetch for a single type of material 'MA%'(using LIKE)
    But for multiple selection of the same fieldi cant do anything ,
    if anybody knows Please Help me.....
    I wil be very thankful if u r helped.
    Regards,
    rajesh.

    I have been trying in the same way
    like
    DATA : sp TYPE char3,
           b3 TYPE char3,
           b5 TYPE char3,
           rt TYPE char3,
           sh TYPE char3,
           rp TYPE char3.
    sp = 'SP%'.
    b3 = 'B3%'.
    b5 = 'B5%'.
    rt = 'RT%'.
    sh = 'SH%'.
    rp = 'RP%'.
    SELECT * FROM
             resb
      INTO   TABLE gt_resb
    WHERE aufnr = wa_itab-aufnr.
    AND matnr LIKE RT.
    OR matnr  LIKE b3
    OR matnr  LIKE b5
    OR matnr  LIKE sh
    OR matnr  LIKE rp
    OR matnr  LIKE sp.
    its not working.
    Regards,
    rajesh S

  • Field selection for mvmt type 543/acct 895000 differs for vendor goods mvmt

    Hi Pals,
              While i post for goods receipt for subcontracting items, it is showing this error
    " Field selection for movement type 543 / acct 895000 differs for vendor goods movement "
    Kindly help me to resolve this plz.
    Thanks&Regards,
    Prasath

    Hello
    what you need to do is, run the program RM07CUFA check for the field status of the particualr movement type for which the system is throwing the error.
    Note that if there is a mandatory entry under G/L account then it should be a mandatory entry under movement type field status also.
    Go to FS00 and Select your GL account and click on Change Mode and in Create/Bank/Interest tab double n Field Status Group.
    Then goto OBC4 and make the change in the field selection for the field status group you got from FS00 for that account. (make the vendor for goods movement as display/optional/required as in the movement type)
    Also see the field selection for movement types in SOMCJ for movement type 543.
    Regards

  • How do you get different check box fields to display based upon a list box selection?

    I am a relative newbie with LifeCycle Designer ES using v.8.2.1 to create interactive forms to replace manual hardcopies.  I am working on a form that has a few pull down list boxes.  I want different check box fields to display based upon the selection of an item from one of the pull down lists.
    Any guidance on the best way to accomplish this would be greatly appreciated.

    Hi,
    Here is a sample with script in the change event of the dropdown. You may want to clear previous checkbox choices once the subform is hidden.
    It is good to group objects in a subform - that way you only need to hide the subform and not each object in turn.
    Good luck,
    Niall

  • Data fields selected in a form are not displaying

    I have selected "Size" & "Outlook Data File" as 2 fields that I need to see on the front tab of all my contacts.  In testing to see if it works I opened a new contact (blank).  Upon it trying to open I get the same error
    twice  "The Property does not exist.  The field you want to modify does not exist for this type of item."  I don't want to modify these two fields, just display them.  I chose the same field names in the forms developer/design
    area as when I added the field as a display cols. in a simple list of contacts (e.g. phone book).  So it works in Viewing a list but I can't see these 2 fields when I add them to a form.  More precisely the labels show, "0" shows as the
    size and blank in the other display field.

    Hi Steve,
    Situation:  Through the yrs I've had multiple email domains.   I've discovered that as I opened and edited contacts they did not always save to my main contact  (.pst) I want to consolidate my contacts to my new one.  
    If I open the same email address from 3-5 different .pst & now MSX too, I want to know which file (domain) they are being displayed from so I don't necessarily have to ck every field to know if I can simply delete one or if I have to go field
    by field to do a merge.  Secondly, I've found that some contacts from older domains never got to my current .MSX so I'm trying to figure the best way to see these.   (Doing an export, then import & then removing dups is not a feasible answer. 
    The exports truncate my notes to 250 chars so I loose too much of my history.)  I added "InFolder" to the contacts form but several say "contacts" so that is not enough to differentiate them.  I tried to go & change the name of the older contacts
    folders but still have 3 contacts folders that I can't seem to change.
    "A field appears in the Field Chooser but it doesn't mean we can use it on every type of Outlook item. We can only use fields appropriate for the form we are designing."  I realize this but these 2 fields are available & display beautifully when
    I select them in my "View" of a list of contacts so it's associated in the OutL database.  Seems logical that it should be on a design form too.
    Is there another suggestion for differentiating where the source of the contact comes from?
    Not sure I follow what you mean by, "We can also post in Outlook for Developers forum to check the properties of Outlook contact form, and confirm which fields we can add to it:" ?? Will this serve as that posting or are you saying post a separate thread?

  • How to merge two search button from different criteria

    How to merge two search button from different criteria
    this image show the question
    http://s24.postimg.org/4algthuj9/1111.jpg
    two different criteria for the same view and I need to merge it in one button as when I click
    on the button search result give from two criteria parameters

    You can!t using af:query. the af:query component comes as is. If you can't do it through the properties, you probably can't do it at all.
    As in your other thread, the way to go is to program your own search form. This way you can use a layout and functionality you like.
    For this you create a form with input fields for the values you are searching for, put them on hte page in a way you like and in the end by hitting on a button (e.g. called Search) map all inputfields to parameters of a service method you defined in your application module or VO. This service method then executes a view criteria returning all matches in the default iterator (just as if you had used af:query.
    Timo 

  • Pull more than one field into the same field in a report.

    I am attempting to put together a report in Visual Studio 2008. It seemed a simple report at first, but as I am creating the SQL, I am having a little trouble conceptualizing how to get it to work exactly as needed. Here is the issue...
    In this case, the report should show two rows for each department. One is the count of who within an audience (that will be set up as a parameter) completed a certain course (the course may also be a parameter). The next row should be
    a count, within that same department, of all users within the audience. Both counts should be within the same field on the report, but on different rows.
    My thought was to create two CTE's. One would contain the counts, by department, of everybody in the audience. The other would contain the counts, by department, of those within the audience who completed the given course.
    The problem is, though, I need to then have these two counts by department on two separate lines, and they should be within the same field. Basically, the idea is they are the numerator and denominator. There would also be a field before the count that would
    need to identify which one it is. For the sake of the example, call it "Measure_ID" and it would say "CourseCert" for the count of who completed the course and "CourseAvail" for the count of those who are part of the audience.
    Let me know if that makes sense, or if I can provide any further clarification to help you better understand what I am trying to achieve. Does anybody have thoughts on how to do this?

    Unfortunately, the counts need to be in separate rows. If they could be in the same row, it would have probably been a lot easier. I think I could have just done a couple "Case When" type formulas within the list of things under "Select."
    As it is, I need the two counts to show up under the same heading in separate rows. Unfortunately, the table structure of this database is very complicated. I think it would likely just further confuse things if I tried to share all of that detail here.
    That is why I was trying to be generic.
    Unless there is another easier way I am missing, I was thinking the easiest way to achieve what I needed was to use two CTE's. One would list all users by department who belong to a specific audience (the audiences are what we use to then assign them
    to certain courses, so the audience would be the people who are required to complete a certain course). The other would list all user by department who are in that audience and have completed a particular course. I think I am fine to complete that part.
    It is just getting them to then display as in my example that I am not sure how to do.
    The desired result, as you see in my example, has two lines per department, the first being a count of those who completed the course ("Certified"). The second line being a count of those who are required to complete it ("Available").
    Does that help? I was basically hoping somebody had an example they could use, just with fake table names so I could adapt it to my data. If it helps, though, let's pretend the two CTE's are like this:
    Table Name: Certified
    Table's purpose: This table would list all people who had completed the course.
    Fields:
    CourseName
    CourseCode
    AudienceName
    AudienceCode
    CompletionResult
    EmpCode
    DepartmentCode
    Table Name: Available
    Table's purpose: This table would list all people who are assigned to the audience.
    Fields:
    AudienceName
    AudienceCode
    EmpCode
    DepartmentCode
    The desired result would then count the EmpCodes, by department, from each table in that Measure_Amount field so it could display as I showed above. Does that make sense? I apologize if that does not help to clarify. I was trying to be as simple
    as possible so you could just use it as a generic example.

  • Pulling more than one field into the same field within a report.

    I posted this in the T-SQL forum, but it was suggested it may be better to post it here. This is somewhat complicated, so I hope I am explaining this well. I will post here what I posted there. I will also include two replies I gave in offering further information
    in case that may help to further clarify my question. See below:
    I am attempting to put together a report in Visual Studio 2008. It seemed a simple report at first, but as I am creating the SQL, I am having a little trouble conceptualizing how to get it to work exactly as needed. Here is the issue...
    In this case, the report should show two rows for each department. One is the count of who within an audience (that will be set up as a parameter) completed a certain course (the course may also be a parameter). The next row should be a count, within that
    same department, of all users within the audience. Both counts should be within the same field on the report, but on different rows.
    My thought was to create two CTE's. One would contain the counts, by department, of everybody in the audience. The other would contain the counts, by department, of those within the audience who completed the given course.
    The problem is, though, I need to then have these two counts by department on two separate lines, and they should be within the same field. Basically, the idea is they are the numerator and denominator. There would also be a field before the count that would
    need to identify which one it is. For the sake of the example, call it "Measure_ID" and it would say "CourseCert" for the count of who completed the course and "CourseAvail" for the count of those who are part of the audience.
    Let me know if that makes sense, or if I can provide any further clarification to help you better understand what I am trying to achieve. Does anybody have thoughts on how to do this?

    Unfortunately, the counts need to be in separate rows. If they could be in the same row, it would have probably been a lot easier. I think I could have just done a couple "Case When" type formulas within the list of things under "Select."
    As it is, I need the two counts to show up under the same heading in separate rows. Unfortunately, the table structure of this database is very complicated. I think it would likely just further confuse things if I tried to share all of that detail here.
    That is why I was trying to be generic.
    Unless there is another easier way I am missing, I was thinking the easiest way to achieve what I needed was to use two CTE's. One would list all users by department who belong to a specific audience (the audiences are what we use to then assign them to
    certain courses, so the audience would be the people who are required to complete a certain course). The other would list all user by department who are in that audience and have completed a particular course. I think I am fine to complete that part. It is
    just getting them to then display as in my example that I am not sure how to do.
    The desired result, as you see in my example, has two lines per department, the first being a count of those who completed the course ("Certified"). The second line being a count of those who are required to complete it ("Available").
    Does that help? I was basically hoping somebody had an example they could use, just with fake table names so I could adapt it to my data. If it helps, though, let's pretend the two CTE's are like this:
    Table Name: Certified
    Table's purpose: This table would list all people who had completed the course.
    Fields:
    CourseName
    CourseCode
    AudienceName
    AudienceCode
    CompletionResult
    EmpCode
    DepartmentCode
    Table Name: Available
    Table's purpose: This table would list all people who are assigned to the audience.
    Fields:
    AudienceName
    AudienceCode
    EmpCode
    DepartmentCode
    The desired result would then count the EmpCodes, by department, from each table in that Measure_Amount field so it could display as I showed above. Does that make sense? I apologize if that does not help to clarify. I was trying to be as simple as possible
    so you could just use it as a generic example.

  • Creating a Material with different values for fields in Transaction MM01

    Hello All,
    While creating a material i will be giving a Profit Center in Sales:general/plant view, which i can see in Costing1 View. If i change this in this View it automatically changes in the other View. Is there any way to give different values in the two views or then what is the significance in showing the same field again in two different views.
    Thanks,
    Shashidhar.

    Hi,
    Its just a way of showing the data in different views for user. It doesn't have any significance.
    Regards,
    Sudheer.

Maybe you are looking for

  • Macbook Air Mid 2013 No Built-In Audio

    Hey everyone, I have an issue with my friends Macbook Air (Mid 2013 Model). After listening to some music through his speakers, he unplugged his Aux cable and then plugged them back in to find that he didnt have built in output or input anymore. I ha

  • Can no longer access remote site in DW CS5

    I've recently upgraded to CS5, when I attempted to upload a PS file to my website in DW I foolishly denied the permissions for CS5.  This has changed my remote server somehow so I can no longer update the website.  Also I've lost all my folders on th

  • Photos don't show/won't copy/show black in slide shows

    I have used iPhoto5 successfully for 2 years on my Powerbook. I accumulated over 8,000 photos so I copied the rolls onto CDs. Seemed to work but when I tried to view the copied pictures they look blank. Also, I can't view an original picture from a r

  • Thinking about switching

    I'm thinking about buying a Mac but I'm having a hard time trying to find answers to my questions. Such as the principle differences between standard computers and Macs and if my progrmas will work on a Mac. Even navigating this site isn't that easy.

  • Hosting DXSI Web Services on Oracle AS 10.1.2.3 ?

    Hi Gurus, I am using Oracle AS 10.1.2.3 and it already hosting Oracle B2B. Is it possible to host DXSI Web Services on the same AS? Thanks in advance, Warm Regards, Suhas.