Help with query where one field is contained in another

I have two tables – t1 and t2 which matches on column a and b. 
I want to create a query that displays rows where column b and do not match or column b contains data in column d. 
I have created the query below but the query is still returning results where fields in column B are contained in column D.
Table
a
b
c
d
100
a
100
a
112
bcd
112
bcde
113
zzzz
113
zzzza
114
ae
114
ae
Output results expected
a
b
c
d
112
bcd
112
bcde
113
zzzz
113
zzzza
select
a
b,
c,
d
from
t1
inner
join
t2
on
t1.a 
= t2.c
and
t1.b
<> t2.d
where
t1.b
not like
+ t2.d
+ '%')

Try below query
select
a
b,
c,
d
from
t1
inner
join
t2
on
t1.a 
= t2.c
and
t1.b
<> t2.d
A-ZSQL

Similar Messages

  • Download to Excel with Header but one field data is repeating

    Hi All,
    I'm downloading to Excel with Header. But One field is repeating and another is not. This is happening only when I use   'CONCATENATE ' . With Out this key usage data download to excel is correct. But   CONCATENATE is required as constant need to add before the one field.
    My coding is as below.
    DATA: BEGIN OF IT_FINAL OCCURS 0,
          P1(10) TYPE C,
          SI(19) type c, 
            END OF IT_FINAL.
    DATA : BEGIN OF IT_HEADER OCCURS 0,
    TITLE(100) TYPE C,
    END OF IT_HEADER,WA_HEADER LIKE IT_HEADER.
    loop at it_final.
      CONCATENATE '894412' it_final-SI INTO IT_FINAL.
    modify it_final.
    endloop.
    CLEAR:WA_HEADER.
      WA_HEADER-TITLE = 'Mat No'.
      APPEND WA_HEADER TO IT_HEADER.
      CLEAR:WA_HEADER.
      WA_HEADER-TITLE = 'Serial'.
      APPEND WA_HEADER TO IT_HEADER.
    CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
        EXPORTING
          FILE_NAME  = P_FILE " path offile where u need to download
        TABLES
          DATA_TAB   = IT_FINAL
          FIELDNAMES = IT_HEADER.
    CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
        EXPORTING
          FILE_NAME  = P_FILE " path offile where u need to download
        TABLES
          DATA_TAB   = IT_FINAL
          FIELDNAMES = IT_HEADER.
    Excel OUT PUT:
    Mat No            Serial
    11Z52321     8944126000
    11Z52394     8944126000
    11Z52395     8944126000
    Thank You,
    Pranitha

    hi,
    it would have been better if u hve opt for creating workarea for ur internal table.
    Try to use "clear it_final" after
    CONCATENATE '894412' it_final-SI INTO IT_FINAL.
    n also change the modify statement :
    modify it_final transporting SI .
    hope this will surely help you
    Regards,
    Punit
    Edited by: punit raval on Aug 26, 2011 2:55 PM

  • How to delete the row in table control with respect to one field in module pool programming?

    Hi,
    Can I know the way to delete the row in table control with respect to one field in module pool programming
    Regards
    Darshan MS

    HI,
    I want to delete the row after the display of table control. I have created push button as delete row. If I click on this push button, the selected row should get deleted.
    I have written this code,
    module USER_COMMAND_9000 input.
    DATA OK_CODE TYPE SY-UCOMM.
    OK_CODE = SY-UCOMM.
    CASE OK_CODE.
         WHEN 'DELETE'.
            LOOP AT lt_source INTO ls_source WHERE mark = 'X'.
                APPEND LS_SOURCE TO LT_RESTORE.
                DELETE TABLE LT_SOURCE FROM LS_SOURCE.
                SOURCE-LINES = SOURCE-LINES - 1.
            ENDLOOP.
    But I'm unable to delete the selected rows, It is getting deleted the last rows eventhough I select the other row.
    So I thought of doing with respect to the field.

  • Can you help with Problems that one of our users i having with regiistration of Premiere Pro?

    Can you help with Problems that one of our users i having with registration of Premiere Pro?

    Link for Download & Install & Setup & Activation problems may help
    -Online Chat http://www.adobe.com/support/download-install/supportinfo/
    More information needed for someone to help... please click below and provide the requested information
    -Premiere Pro Video Editing Information FAQ http://forums.adobe.com/message/4200840

  • Copy BEx Query from one SAP BI system to another SAP BI system?

    Experts please help me to Copy a BEx Query from one SAP BI system to another SAP BI system?
    Thanks in Advance.......

    HI,
    Just assume like below,
    you are creating your query in Development server(BI),
    Before creating query, you go to SE09(t code), here you create a workbench request by clicking the create button.
    Give some description here to be identified by you in future.
    Now a requested will be generated(ex: DW5K50098) with prefix of your server name.
    now you go to query designer, you create query, when you save the query, it will ask you request, now you click button 'own request'. you choose request(create by you in SE09).
    it will be saved under this request, now you will have one more request under your request in SE09
    parent request(DW5K50098) and child request(DW5K50099).
    First you click child request and relese(click lorry button in se09),second you click parent request and lorry button.
    next steps will be related to your organization, you can ask your team leader, he will be taking care of it.
    Regards,
    Ranganath.

  • Help with query calculations (recursive)

    Hi All,
    I want some help with a query using a base rate and the result use in the next calculation year.
    Here an example:
    create table rate_type(
    rate_type_id    number,
    rate_desc       nvarchar2(50),
    rate_base_year  number
    insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (1, 'Desc1', 4.6590);
    insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (2, 'Desc2', 4.6590);
    create table rates (
    rate_type_id number
    rate_year    number,
    rate_value   number
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2012, 1.2);
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2013, 1.3);
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2014, 1.4);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2012, 1.2);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2013, 1.3);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2014, 1.4);The calculation for the first year should be the base rate of the rate type. The next year should use the result of the previous year and so on.
    The result of my sample data is:
    2012 = 4.659 + 1.2 + 4.659 * (1.2 * 0.01) = 5.9149
    2013 = 5.9149 + 1.3 + 5.9149 * (1.3 * 0.01) = 7.1859
    2014 = 7.1859 + 1.4 + 7.1859 * (1.4 * 0.01) = 8.4721Query result:
    NAME 2012 2013 2014
    Desc1 5.9149 7.1859 8.4721
    Desc2 XXXX XXX XXXX
    How can I do this in one select statement? Any ideas?
    Thanks!

    Assuming you are on 11.2:
    with t as (
               select  a.rate_type_id,
                       rate_desc,
                       rate_year,
                       rate_base_year,
                       rate_value,
                       count(*) over(partition by a.rate_type_id) cnt,
                       row_number() over(partition by a.rate_type_id order by rate_year) rn
                 from  rate_type a,
                       rates b
                 where a.rate_type_id = b.rate_type_id
        r(
          rate_type_id,
          rate_desc,
          rate_year,
          rate_base_year,
          rate_value,
          cnt,
          rn,
          result
         ) as (
                select  rate_type_id,
                        rate_desc,
                        rate_year,
                        rate_base_year,
                        rate_value,
                        cnt,
                        rn,
                        rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
                  from  t
                  where rn = 1
               union all
                select  t.rate_type_id,
                        t.rate_desc,
                        t.rate_year,
                        t.rate_base_year,
                        t.rate_value,
                        t.cnt,
                        t.rn,
                        r.result + t.rate_value + r.result * t.rate_value * 0.01 result
                  from  r,
                        t
                  where t.rate_type_id = r.rate_type_id
                    and t.rn = r.rn + 1
    select  *
      from  (
             select  rate_desc name,
                     rate_year,
                     result
               from  r
               where rn <= cnt
      pivot (sum(result) for rate_year in (2012,2013,2014))
      order by name
    NAME             2012       2013       2014
    Desc1        5.914908  7.2918018 8.79388703
    Desc2        5.914908  7.2918018 8.79388703
    SQL> Obviously pivoting assumes you know rate_year values upfront. If not, then without pivoting:
    with t as (
               select  a.rate_type_id,
                       rate_desc,
                       rate_year,
                       rate_base_year,
                       rate_value,
                       count(*) over(partition by a.rate_type_id) cnt,
                       row_number() over(partition by a.rate_type_id order by rate_year) rn
                 from  rate_type a,
                       rates b
                 where a.rate_type_id = b.rate_type_id
        r(
          rate_type_id,
          rate_desc,
          rate_year,
          rate_base_year,
          rate_value,
          cnt,
          rn,
          result
         ) as (
                select  rate_type_id,
                        rate_desc,
                        rate_year,
                        rate_base_year,
                        rate_value,
                        cnt,
                        rn,
                        rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
                  from  t
                  where rn = 1
               union all
                select  t.rate_type_id,
                        t.rate_desc,
                        t.rate_year,
                        t.rate_base_year,
                        t.rate_value,
                        t.cnt,
                        t.rn,
                        r.result + t.rate_value + r.result * t.rate_value * 0.01 result
                  from  r,
                        t
                  where t.rate_type_id = r.rate_type_id
                    and t.rn = r.rn + 1
    select  rate_desc name,
            rate_year,
            result
      from  r
      where rn <= cnt
      order by name,
               rate_year
    NAME        RATE_YEAR     RESULT
    Desc1            2012   5.914908
    Desc1            2013  7.2918018
    Desc1            2014 8.79388703
    Desc2            2012   5.914908
    Desc2            2013  7.2918018
    Desc2            2014 8.79388703
    6 rows selected.
    SQL> SY.

  • Need help with querying users

    It only displays the correct amount of members when I queried only one group like this:
    select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1"
    When I tried for multiple groups like shown below, it shows 0 member. I received no error for the query though it is obviously wrong. 
    select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1" and SMS_R_User.SecurityGroupName = "domain\\security
    group2" and SMS_R_User.SecurityGroupName = "domain\\security group3"
    Please check and help me correct it so I can get all members in one collection.
    Thanks

    Hi,
    If you look to query the amount of members in all the groups you define, use OR instead of AND.
    When you use AND, you define that the result must be a member of group1 AND group2 AND group3. You should use OR to get the members of the groups, even though they're just a member of one of them.
    select SMS_R_USER.ResourceID,SMS_R_USER.ResourceType,SMS_R_USER.Name,SMS_R_USER.UniqueUserName,SMS_R_USER.WindowsNTDomain from SMS_R_User where SMS_R_User.SecurityGroupName = "domain\\security group1" or SMS_R_User.SecurityGroupName = "domain\\security
    group2" or SMS_R_User.SecurityGroupName = "domain\\security group3"
    All the best, Jesper Hassing - MCTS SCCM 2012 - MCSA 2012 Server - MCP

  • Help with query Condition

    --Sample create/insert :
    create table xxdummy(
    id integer,
    name varchar2(40),
    description varchar2(100)
    insert into xxdummy values (1,'L', 'Simple L press');
    insert into xxdummy values (2,'XL', 'XL with no film');
    insert into xxdummy values (2,'web', 'XL with no film');
    insert into xxdummy values (3,'XL', 'XL with Film');
    insert into xxdummy values (3,'Film', 'XL with Film');
    insert into xxdummy values (3,'print', 'XL with Film');
    insert into xxdummy values (4,'S', 'servo with film');
    insert into xxdummy values (4,'Film','servo with film' );
    insert into xxdummy values (5,'S','only servo' );
    insert into xxdummy values (6,'L', 'Simple L press');
    insert into xxdummy values (7,'XL', 'XL with no film');
    insert into xxdummy values (8,'XL', 'XL with Film');
    insert into xxdummy values (8,'Film', 'XL with Film');
    insert into xxdummy values (8,'guide', 'XL with Film');
    --drop table xxdummy;
    select * from xxdummy;
    select id, description, decode(name, 'L', 'L Only', 'XL', 'Got XLs here', 'dont know' ) type
    from xxdummy
    where name in ('L','XL' )
    In above query for column type, I want to display 'L Only', 'XL With Film', 'XL Without Film'
    How can I do this ?
    Thanks

    I should have explained more, but my mind is so fried making up sample replica of the data as its scattered over so many tables in the original query taht I couldnt put it properly:
    another try :
    column Description is just for my reference , So please ignore that for now.
    I have to form a condition only using colums name and id.
    select * from xxdummy :
    id=2 and 7 , has name=XL but doesnt have 'Film' so I want to mark this row as 'XL with no film'
    id=3 and 8 , has name=XL and also has name = Film, So label for this should be - XL With Film
    id=4 , has name=S and also Film, --All the ids that have name=S, no matter if it has film with same Id should be excluded.
    id=5, exclude it
    id=1 and 6 have name = L , Lable them 'L Only' .
    So I should basically have 6 rows returned in my sample data :
    select id, description, name, decode(name, 'L', 'L Only', 'XL', 'Got XLs here' ,'dont know') type
    from xxdummy
    where name in ('L','XL')
    how do I distinguish within id, that has name=XL : which one has film and which one doesnt
    did it sound better ?
    Edited by: OAF-dev on Nov 17, 2009 4:10 PM

  • Help with more than one apple id on same computer

    When my husband tries to do anything in his itunes library he gets the following error message,
    "This computer is already associated with an apple id  You can download past purchases on this computer with just one apple id every 90 days.  This computer can be used with a different Apple id in 11 days"
    I HAS been approx 3 months (90 days) since we purchased a new computer-but we have always had different itunes libraries.  HELP!!

    Only one account can be signed in at a time (via Settings > Store), and if you turn on automatic downloads and/or download past purchases from an account then you risk tying the iPad to that account for 90 days : http://support.apple.com/kb/HT4627

  • Need help with Workflow Issue: One notification sending out non-stop email.

    Hi,
    We've created a custom PO Approval Workflow based on standard PO Approval Workflow and we've had this for a while now. Last week, we encountered an issue where the notification keeps on sending email to the Suppliers and Buyers. We found out that the particular notification_id in the WF_NOTIFICATIONS table keeps getting updated by the minute setting the MAIL_STATUS to INVALID then back to SENT then back to INVALID again and so on. We think that whatever is updating this table is the cause but up until now we haven't found what's updating it. Below are some information of our instance.
    Oracle Applications: 11.5.10.2
    Database: 10.2.0.4 64 bit
    OS: AIX
    Custom Workflow based on revision 115.127.11510.16
    Customizations:
    - Created custom notification XX_EMAIL_PO_PDF_SUPP based on EMAIL_PO_PDF_SUPP.
    - Created custom message XX_EMAIL_PO_PDF based on EMAIL_PO_PDF.
    - Added #WFM_CC to XX_EMAIL_PO_PDF.
    - Created custom attribute XX_PO_WF_EMAIL_PERFORMER and set as Performer to notification XX_EMAIL_PO_PDF_SUPP.
    - Created custom function XX_ADDTL_STARTUP_VAL right after function "Set Workflow Startup Values". This function sets #WFM_CC attribute and XX_PO_WF_EMAIL_PERFORMER attribute.
    Not sure if the customizations have anything to do with the issue since not all POs have this issue. Have anyone experience this? Would really appreciate any help with this.
    Thanks,
    Allen

    Kashif M wrote:
    Just review this thread, may help you
    Workflow Notification Mailer is Spamming the Email Accounts of Users [ID 1293792.1]
    thanksHi,
    This note has solved our issue. Hopefully they will release a fix for this as it is a common thing for us to change the email address of Supplier Site.
    Thanks,
    Allen

  • Help with my iPad one.

    My iPad one keeps crashing. It never crashed before ios5. Now it even crashes when using Apple apps like Safari. I have done e latest upgrade.

    Start with easy steps. Restart your iPad and if that doesn't help - maybe resetting it will help.
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    You can also try quitting apps and restarting the iPad.
    Go to the home screen first by tapping the home button. Quit/close open apps by double tapping the home button and the task bar will appear with all of you recent/open apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus (-) sign in the upper left corner to close the apps. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Clearing Safari may help with crashes in that app as well.
    Go to Settings>Safari>Clear History, Cookies and Data. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.

  • How to form an Endeca query where a field must start with certain letters

    hi, Is it possible to form an Endeca query to retrieve a field that must start with certain letters? Say like get all users who's first letter is 'A' ? I checked with Range filters but it is supporting only numerical fields as well as Wild card search. But nothing worked well so far. any suggestion?

    Yes. Here's the gist of how it works:
    Typeahead is commonly implemented by enabling wildcard search on one or more Dimensions. An AJAX query is sent out containing the beginning of a search term. A controller in the app layer answers that AJAX query and formulates an Endeca Dimension Search query. It sends that off to the Endeca MDEX engine. Endeca responds with relevant Dimension matches. The controller returns these to the client who made the AJAX request. They are rendered as hyperlinks that lead to a particular navigation state in the catalog.

  • Help with query - multiple where in grouped column

    4 columns in table named RRID1
    RRI_ID
    USER_ID
    PROCESS_TYPE
    FUNCTION
    not sure how to make this query.
    Need to pull all RRI_ID's where PROCESSTYPE ='INFO' and PROCESSTYPE ='RESOLUTION'
    for that RRI_ID.
    so same user, same RRI_ID and 2 process records, 1 INFO and 1 RESOLUTION
    so not if there is duplicate info, just if there is info and resolution.
    This is what some of data looks like..
    PROCESSTYPE|USER_ID|FUNCTION|RRI_ID
    INFO 3668 30287 817
    INFO 3748 30287 817
    INFO 4714 30287 817
    INFO 4875 30287 817
    INFO 4882 30287 817
    INFO 4885 30287 817
    INFO 3748 30288 818
    INFO 4714 30288 818
    INFO 4716 30288 818
    INFO 4882 30288 818
    INFO 4885 30288 818
    INFO 3668 30289 819
    INFO 4716 30289 819
    INFO 4875 30289 819
    INFO 4882 30289 819
    INFO 4885 30289 819
    INFO 3668 30290 820
    INFO 4716 30290 820
    INFO 4875 30290 820
    INFO 4882 30290 820
    INFO 4885 30290 820
    INFO 3668 30291 821
    INFO 4714 30291 821
    INFO 4716 30291 821
    INFO 4875 30291 821
    INFO 4882 30291 821

    you will have a stroke before you hit 40That's not the point, but thanks for your concern and you'll probably end up having a stroke sooner than me if you keep asking questions this way ;)
    Point is: stick to your original thread/question, keep it all together, be complete, instead of reposting and starting all over again.
    It's confusing when you start a new thread, while the context of your old thread matters.
    While Blu seemed to be correct, you changed the question in your previous thread after his answer and started a new one, with the same 'data'.
    Hence me being a 'nit-picker', because by starting multiple threads:
    - you'll get the right answer slower, maybe much slower
    - we're assuming things that might be out of context, given your previous thread
    etc.

  • 11g: Multicolumn pivot - help with query

    Hi everyone,
    My first attempt at posting here was not very successful. I have now read the rules, and done more homework.
    I'm fairly new to Oracle databases, but have some experience with MySQL and Postgres from earlier.
    First of all, here is an example table of what I have today. This is only an extract of the full table, but these fields are the interesting ones.
    CREATE TABLE trans
         ("FROM_LIC" int, "FROM_LOCATION" varchar2(18), "TO_LOCATION" varchar2(18), "CREATE_DT" timestamp)
    INSERT ALL
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, '215', 'INN_MONO_05', '04-Mar-2013 11:54:21 AM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, 'INN_MONO_05', 'INN_MONO_06_BANE_R', '04-Mar-2013 11:55:08 AM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, 'INN_MONO_06_BANE_R', 'TROLLEY_19', '04-Mar-2013 12:01:06 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, 'TROLLEY_19', 'UT_OPPLAST_5_2', '04-Mar-2013 12:01:56 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, 'UT_OPPLAST_5_2', 'STG010801', '04-Mar-2013 12:01:56 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003259, '231', 'INN_MONO_04', '04-Mar-2013 02:18:31 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003259, 'INN_MONO_04', 'INN_MONO_04_BANE_L', '04-Mar-2013 02:19:28 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003259, 'INN_MONO_04_BANE_L', 'TROLLEY_5', '04-Mar-2013 02:22:41 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003259, 'TROLLEY_5', 'UT_OPPLAST_3_1', '04-Mar-2013 02:23:35 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, '243', 'INN_MONO_06', '04-Mar-2013 01:37:49 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, 'INN_MONO_06', 'INN_MONO_06_BANE_R', '04-Mar-2013 01:39:09 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, 'INN_MONO_06_BANE_R', 'TROLLEY_10', '04-Mar-2013 01:43:48 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, 'TROLLEY_10', 'UT_OPPLAST_5_2', '04-Mar-2013 01:44:58 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, 'UT_OPPLAST_5_2', 'STG010904', '04-Mar-2013 01:46:30 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003263, '231', 'INN_MONO_04', '04-Mar-2013 02:18:31 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003263, 'INN_MONO_04', 'INN_MONO_04_BANE_R', '04-Mar-2013 02:19:20 PM')
    SELECT * FROM dual
    ;As of now, I have a query that returns a data grid from the table, looking exactly like the example table I've included.
    Here is a copy of the query that gives the example table as a result from the table in our database:
    select * from (
        select distinct from_lic, from_location, to_location, create_dt from trans where to_location like 'INN_MONO___' and create_dt > sysdate-(3/24)
        union
        select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO___' and to_location like 'INN_MONO%BANE%' and create_dt > sysdate-(3/24)
        union
        select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO%BANE%' and to_location like 'TROLLEY%' and create_dt > sysdate-(3/24)
        union
        select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'TROLLEY%' and to_location like 'UT_OPPLAST____' and create_dt > sysdate-(3/24)
        union
        select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'UT_OPPLAST____%' and (to_location like 'STG%' or to_location like 'UT_OPPLAST%GULV') and create_dt > sysdate-(3/24)
      ) order by from_lic, create_dtI would be delighted if you could help me formulating a new query that gives THIS output, from the same table, with the same constraints as in the original query:
    CREATE TABLE new_table
         ("FROM_LIC" int, "FLOOR" timestamp, "INFEED" timestamp, "TROLLEY" timestamp, "OUTFEED" timestamp, "STAGING" varchar2(16))
    INSERT ALL
         INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
               VALUES (4100002563, '04-Mar-2013 11:54:00 AM', '04-Mar-2013 11:55:00 AM', '04-Mar-2013 12:01:00 PM', '04-Mar-2013 12:01:00 PM', '03.04.2013 12:01')
         INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
               VALUES (4100003259, '04-Mar-2013 02:18:00 PM', '04-Mar-2013 02:19:00 PM', '04-Mar-2013 02:22:00 PM', '04-Mar-2013 02:23:00 PM', NULL)
         INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
               VALUES (4100003262, '04-Mar-2013 01:37:00 PM', '04-Mar-2013 01:39:00 PM', '04-Mar-2013 01:43:00 PM', '04-Mar-2013 01:44:00 PM', '03.04.2013 13:46')
    SELECT * FROM dual
    ;What happened here is that for each instance of from_lic, the line yielded from
    select distinct from_lic, from_location, to_location, create_dt from trans where to_location like 'INN_MONO___' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> in the new column called FLOOR.
    And the following for the rest of the columns:
    select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO___' and to_location like 'INN_MONO%BANE%' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> INFEED.
    select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO%BANE%' and to_location like 'TROLLEY%' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> TROLLEY.
    select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'TROLLEY%' and to_location like 'UT_OPPLAST____' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> OUTFEED.
    select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'UT_OPPLAST____%' and (to_location like 'STG%' or to_location like 'UT_OPPLAST%GULV') and create_dt > sysdate-(3/24)The value for CREATE_DT ---> STAGING.
    Originally I was thinking of a pivot for this, but there is possibly better ways to accomplish this.
    I would like to have the data in the described format to make data mining easier.
    The query will run on a table with >3M lines.
    I hope this way of formulating the question is better, and more comprehensible.
    Please do not hesitate to ask questions, and I'll do my best to answer.
    I can test any suggested queries in the production database when necessary.
    Edited by: 997749 on Apr 3, 2013 5:18 AM
    Edited by: 997749 on Apr 3, 2013 6:20 AM

    Hi,
    what about something like this:
    with trans as
       SELECT 4100002563 from_lic, 'INN_MONO_05'        to_location, TO_DATE('03.04.2013 11:54:21', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100002563 from_lic, 'INN_MONO_06_BANE_R' to_location, TO_DATE('03.04.2013 11:55:08', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100002563 from_lic, 'TROLLEY_19'         to_location, TO_DATE('03.04.2013 12:01:06', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100002563 from_lic, 'STG010801'          to_location, TO_DATE('03.04.2013 12:01:56', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100002563 from_lic, 'UT_OPPLAST_5_2'     to_location, TO_DATE('03.04.2013 12:01:56', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'INN_MONO_05'        to_location, TO_DATE('03.04.2013 11:18:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'INN_MONO_04_BANE_R' to_location, TO_DATE('03.04.2013 11:21:54', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'TROLLEY_16'         to_location, TO_DATE('03.04.2013 11:25:43', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'UT_OPPLAST_3_4'     to_location, TO_DATE('03.04.2013 11:26:37', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'STG010703'          to_location, TO_DATE('03.04.2013 11:27:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100006658 from_lic, 'INN_MONO_08'        to_location, TO_DATE('03.04.2013 11:00:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100006658 from_lic, 'INN_MONO_08_BANE_L' to_location, TO_DATE('03.04.2013 11:02:35', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100006658 from_lic, 'TROLLEY_22'         to_location, TO_DATE('03.04.2013 11:07:54', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100006658 from_lic, 'UT_OPPLAST_7_3'     to_location, TO_DATE('03.04.2013 11:09:03', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL
    , got_category AS
       SELECT from_lic
            , CASE
                 WHEN to_location like 'INN_MONO%BANE%'
                 THEN 'INFEED'
                 WHEN to_location like 'INN_MONO%'
                 THEN 'FLOOR'
                 WHEN to_location like 'TROLLEY%'
                 THEN 'TROLLEY'
                 WHEN to_location like 'STG' OR to_location like 'UT%GULV' 
                 THEN 'STAGED'
                 WHEN to_location like 'UT_OPPLAST%'
                 THEN 'OUTFEED'
                 ELSE 'UNKNOWN'
              END as cat
            , create_dt
         FROM trans
        WHERE create_dt > (sysdate -10/24) -- adjusted for different timezone
    SELECT * --FROM_LIC, lic_a, lic_b, lic_c, lic_d, lic_e
      FROM got_category
    PIVOT(MAX(create_dt) FOR cat IN('FLOOR'   as floor,
                                     'INFEED'  as infeed,
                                     'TROLLEY' as trolley,
                                     'OUTFEED' as ooutfeed,
                                     'STAGED'  as staged));
      FROM_LIC FLOOR                  INFEED                 TROLLEY                OOUTFEED               STAGED               
    4100002563 03-APR-2013 11:54:21   03-APR-2013 11:55:08   03-APR-2013 12:01:06   03-APR-2013 12:01:56                        
    4100005037 03-APR-2013 11:18:31   03-APR-2013 11:21:54   03-APR-2013 11:25:43   03-APR-2013 11:26:37                        
    4100006658 03-APR-2013 11:00:31   03-APR-2013 11:02:35   03-APR-2013 11:07:54   03-APR-2013 11:09:03                         If not useful, please post your input data (CREATE TABLE and INSERT statements) and your expected output.
    Regards.
    Al

  • Need help with query that can look data back please help.

    hi guys i have a table like such
    CREATE TABLE "FGL"
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )and i have a data like such
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');I bascially need to get the total of the budget column. however its not as simple as it sound(well atleast not for me.) the totals carry over to the new period. youll noticed the you have a period column. basically what im saying is that
    fgl_grant_year 10 period 1 = for account 7600 its $100 and $100 for period 2 you see 100 dollars again this is not to be added this is the carried over balance. which remains $100.
    so im trying to write a query that basically does the following.
    im given a period for the sake of this example lets say period 1 i get nothing else. I have to find the greates grant year grab the amount for period 14(which is the total from the previous year) and add it to the amount of the current period. in this case period 1 grnt_year 11
    so the expected outcome should be $700
    240055     240055     7240     4730     02     10     14     200
    240055     240055     7600     4730     02     10     14     100
    240055     240055     7600     4730     02     11     1     400keep in mind that im not given a year just a period.
    any help that you guys can offer would be immensely appreciated. I have been trying to get this to work for over 3 days now.
    finally broke down and put together this post
    Edited by: mlov83 on Sep 14, 2011 8:48 PM

    Frank
    wondering if you can help me modify this sql statement that you provided me with .
    table values have been modified a bit.
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');i need to take one more thing into consideration. if the greatest year has a value on period 00 i need to ignore the period 14 and the current period total would be
    the current period +(current period - greatest year 00)
    hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
    because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
    period 2 amount $ 600
    period 0 amount $ 400 - period 2 amount of $600 = 200
    600+200 = $800
    if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
    i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
    can you please help me out.
    Miguel

Maybe you are looking for

  • How do i transfer a new album to my iPod from iTunes without overwriting my library on the iPod

    If i try to add a new album or song to my iPod from iTunes all the other data is deleted. How do i do this without having to trasnefer my entire library every time i have new music to add?

  • Brilliant way to create titles from text files

    It was just pointed out to me by a fellow named Greg Hester that there is a way to create titles from a Microsoft Word file using Adobe InDesign. You can create as many titles as you need, and even change text positions around from title to title. Th

  • Copy/Paste function no longer works in iOS5?

    Just upgraded to iOS5 last night, and I just noticed I can no longer copy/paste from Safari to Office HD. It goes through all the motions, but there is no text pasted. I tried rebooting, same deal. I can paste the text in notes, but it doesn't work i

  • YoiTube isn't recognizing Flash in Safari gor Windows?

    Hi, I recently downloaded Safari for Windows, and upon visiting Youtube, YouTube gave me a message saying my browser wasn't supported. I ignored the message and whenever I try to play a YouTube video with either Flash or QuickTime, it doesn't work. I

  • How do I highlight apps when hovered over?

    There is a Terminal command line that will do this, but I can't remember what it is. What I want to do, is when I hover over an app, in the apps folder on the Dock, I want it to highlight that that app my mouse cursor is over. I used to have this ena