Two conditions in where part of the query out of which 1 is based on length

hi
am having two tables and i need to join them to get my desired output. let me explain with example
table A contains data like
>
col1 col2 col3
12345 sons abcd
23456 snms bcde
34567 snms nil
56478 sons ..
>
table B contains data like
>
col-1 col-2 col-3
sons not-subscribed 0
sons nil-balance 111
snms not-subscribed 0
snms incorrect 111
soai incorrect 111
>
i need the output like
>
col1_of_table_A col3_of_table_A col-2_of_table_B
12345 abcd nilbalance
23456 bcde incorrect
34567 nil not-subscribed
56478 .. not-subscribed
>
likely requirement in sample query format is
select a.col1,a.col3,b.col-2 from A a, B b where ((a.col2=b.col-1 and length(a.col3)>length(b.col-3)) or (a.col2=b.col-1 and length(a.col3)<length(b.col-3)))how to achieve this conditional joint?

Hi,
in your query i just added '..' instead of null for the row starting with 56478 in table A and executed the query as below and it doesn't give my desired output.
with a  as
     select 12345 as col1, 'sons' as col2, 'abcd' as col3 from dual union all
    select 23456, 'snms', 'bcde' from dual union all
    select 34567, 'snms', 'nil' from dual union all
  select 56478, 'sons', '..' from dual
   , b as
     select 'sons' col1, 'not-subscribed' col2, 0 col3 from dual union all
    select 'sons', 'nil-balance', 111 from dual union all
     select 'snms', 'not-subscribed', 0 from dual union all
    select 'snms', 'incorrect', 111 from dual union all
    select 'soai', 'incorrect', 111 from dual
   select  col1, col3, col2
  from
       select a.col1,a.col3,b.col2, row_number() over (partition by a.col1 order by b.col2) rn
        from A a
         left outer join b on (
                              (    a.col2         = b.col1
                               and  length(a.col3) > length(b.col3)
                              or
                               (    a.col2         = b.col1
                               and length(a.col3)  < length(b.col3)
  where rn = 1
  output is
>
COL1     COL3     COL2
12345     abcd     nil-balance
23456     bcde     incorrect
34567     nil     not-subscribed
56478     ..     nil-balance
>
what could be problem?

Similar Messages

  • DECODE in the WHERE part of the query ?

    Hello guys ,I am on 10gR2, and as always , the following mystery for me will be funny for you : ), so please share your knowledge.
    I have one select on v$session , and i would to use something like DECODE function in the WHERE part of the query,
    but , for the values i enter through the variables.
    Currently i have something like :
    WHERE status =upper('&session_status') AND username IS NOT NULL order by last_call_et desc;and that works fine, i enter either 'active' or 'inactive' and i get results.
    But i would like to enter for example '1' for active and '2' for inactive, so i could write as little as i can as i am lazy. : )
    Do you have some idea ?

    hi there
    select * from v$session  where status = decode('&session_status',1,'ACTIVE','INACTIVE')  AND username IS NOT NULL order by last_call_et descregards
    hitesh

  • Uploading a text file from webi filter area as part of the query condition

    Post Author: balasura
    CA Forum: Publishing
    Requirement : Uploading a text file from webi filter area as part of the query condition Hi, I am in a serious requirement which I am not sure available in BO XI. Can some one help me plz. I am using BO XI R2, webi I am generating a ad-hoc report, when I want to give a filter condition for a report, the condition should be uploaded from a .txt file. In the current scenario we have LOV, but LOV could hold only a small number of value, my requirement is just like a lov but the list of values will be available in a text file ( which could number to 2000 or 2500 rows). I would like to upload this 2500 values in the form of a flat text file to make a query and genrate report. Is it possible in BO XI? For Eg:- Select * from Shipment Where u201CShipment id = u2018SC4539u2019 or Shipment id = u2018SC4598u2019u201D The u201Cwhereu201D condition (filter) which has shipment id will be available in a text file and it needs to be loaded in the form of .txt file so that it will be part of the filter condition. Content of a .txt file could be this shipment.txt =============== SC4539 sc2034 SC2343 SC3892 . . . . etc upto 2500 shipment Ids I will be very glad if some could provide me a solution. Thanks in advance. - Bala

    Hi Ron,
       This User does not have the access to Tcode ST01.
       The user executed Tcode SU53 immediately following the authorization failure to see the authorization objects. The 'Authorization obj' is blank and under the Description it has 'The last Authorization check was successful' with green tick mark.
      Any further suggestions, PLEASE.
    Thanks.

  • How can I pass multiple condition in where clause with the join table?

    Hi:
    I need to collect several inputs at run time, and query the record according to the input.
    How can I pass multiple conditions in where clause with the join table?
    Thanks in advance for any help.
    Regards,
    TD

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

  • I have a macbookpro with a second monitor connected using an Apple connector.  The two screens show different parts of the desktop.  My cat walked across the keyboard, and now the two monitors are showing the same thing.  How do I undo what the cat did?

    I have a macbookpro with a second monitor connected using an Apple connector.  The two screens show different parts of the desktop.  My cat walked across the keyboard touching various keys, and now the two monitors are showing the same thing.  How do I undo what the cat did?

    Have you tried HELP in FINDER?  If you open HELP and enter 'displays' in the field in the upper right hand corner you will get a list of topics on setting up monitors.  Specifically read 'Setting up multiple displays to show the same image' and 'Setting up multiple displays as an extended desktop'.
    Ciao.

  • Using a list in the where part of my query

    I don't want to bother getting results for everyone in my DB.
    I only want to retreive information from a list of up to 5
    people - the list will constantly change.
    I started with code below:
    <cfparam name="useYear" default="Year(now())">
    <!--- LIST --->
    <cfset riderList="1,5,10,18,53">
    <cfloop index="i" from="1" to="#ListLen(riderList)#">
    <cfquery name="getRiderSum" datasource="mileage">
    SELECT riderId,
    SUM(IIf(month(rideDate)=1, rideDistance, 0)) AS janSum,
    SUM(IIf(month(rideDate)=2, rideDistance, 0)) AS febSum,
    SUM(IIf(month(rideDate)=3, rideDistance, 0)) AS marSum,
    SUM(IIf(month(rideDate)=4, rideDistance, 0)) AS aprSum,
    SUM(IIf(month(rideDate)=5, rideDistance, 0)) AS maySum,
    SUM(IIf(month(rideDate)=6, rideDistance, 0)) AS junSum,
    SUM(IIf(month(rideDate)=7, rideDistance, 0)) AS julSum,
    SUM(IIf(month(rideDate)=8, rideDistance, 0)) AS augSum,
    SUM(IIf(month(rideDate)=9, rideDistance, 0)) AS sepSum,
    SUM(IIf(month(rideDate)=10, rideDistance, 0)) AS octSum,
    SUM(IIf(month(rideDate)=11, rideDistance, 0)) AS novSum,
    SUM(IIf(month(rideDate)=12, rideDistance, 0)) AS decSum
    FROM mileageLog
    WHERE riderId=#i#
    AND Year(rideDate)=#useYear#
    GROUP BY riderId
    </cfquery>
    </cfloop>
    but how do I keep the information ordered by the riderId?
    do I utilize the "i" as part of my query name?...
    name="getRiderSum
    do I utilize it as part of each monthly variable? ... AS
    janSum etc.

    You don't need a cfloop. Try an IN(...) clause instead.
    Obviously you have to validate that the #riderlist# is not empty
    first or the query will error.
    SELECT riderId,
    SUM(IIf(month(rideDate)=1, rideDistance, 0)) AS janSum,
    SUM(IIf(month(rideDate)=2, rideDistance, 0)) AS febSum,
    SUM(IIf(month(rideDate)=3, rideDistance, 0)) AS marSum,
    SUM(IIf(month(rideDate)=4, rideDistance, 0)) AS aprSum,
    SUM(IIf(month(rideDate)=5, rideDistance, 0)) AS maySum,
    SUM(IIf(month(rideDate)=6, rideDistance, 0)) AS junSum,
    SUM(IIf(month(rideDate)=7, rideDistance, 0)) AS julSum,
    SUM(IIf(month(rideDate)=8, rideDistance, 0)) AS augSum,
    SUM(IIf(month(rideDate)=9, rideDistance, 0)) AS sepSum,
    SUM(IIf(month(rideDate)=10, rideDistance, 0)) AS octSum,
    SUM(IIf(month(rideDate)=11, rideDistance, 0)) AS novSum,
    SUM(IIf(month(rideDate)=12, rideDistance, 0)) AS decSum
    FROM mileageLog
    WHERE riderId IN (<cfqueryparam value="#riderList#"
    cfsqltype="the column type here" list="true"> )
    AND Year(rideDate)=#useYear#
    GROUP BY riderId
    ORDER BY riderId

  • Performance hit using "where" clause in the query

    Hi All,
    I am facing a huge performance hit in the java code when using "where" clause in queries. Following are the details:
    1. SELECT * FROM Employee
    2. SELECT * FROM Employee where employeeid in (26,200,330,571,618,945)
    There is no difference in Query Execution Time for both queries.
    Business Logic Time is huge in second case as compared to first one (ratio - 1:20).
    Rows returned are more in first case as compared to second case.(ratio - 1:4)
    Business Logic is same for both the cases where I iterate through the ResultSet, get the objects and set them in a data structure.
    Does anybody know the reason of unexpected time difference for the business logic in the second case?

    Since you're mentioning clustering your index, I'll assume you are using Oracle. Knowing what database you are using makes it a lot easier to suggest things.
    Since you are using Oracle, you can get the database to tell you what execution plan it is using for each of the 2 SQL statements, and figure out why they have similar times (if they do).
    First, you need to be able to run SQL*Plus; that comes as part of a standard database installation and as part of the Oracle client installation - getting it set up and running is outside the scope of this forum.
    Second, you may need your DBA to enable autotracing, if it's not already:
    http://asktom.oracle.com/~tkyte/article1/autotrace.html
    http://www.samoratech.com/tips/swenableautotrace.htm
    Once it's all set up, you can log in to your database using sql*plus, issue "SET AUTOTRACE ON", issue queries and get execution plan information back.
    For example:
    SQL> set autotrace on
    SQL> select count(*) from it.ticket where ticket_number between 10 and 20;
      COUNT(*)
            11
    Execution Plan
    Plan hash value: 2983758974
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            |     1 |     4 |     1   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE   |            |     1 |     4 |            |          |
    |*  2 |   INDEX RANGE SCAN| TICKET_N10 |    12 |    48 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TICKET_NUMBER">=10 AND "TICKET_NUMBER"<=20)
    Statistics
              0  recursive calls
              0  db block gets
              1  consistent gets
              0  physical reads
              0  redo size
            515  bytes sent via SQL*Net to client
            469  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL> This tells me that this query used an INDEX RANGE SCAN on index TICKET_N1; the query can't do much better than that logically... In fact, the statistic "1 consistent gets" tells me that Oracle had to examine only one data block to get the answer, also can't do better than that. the statistic, "0 physical reads" tells me that the 1 data block used was already cached in Oracle's memory.
    the above is from Oracle 10g; autotrace is available back to at least 8i, but they've been adding information to the output with each release.
    If you have questions about sql_plus, check the forums at asktom.oracle.com or http://forums.oracle.com/forums/category.jspa?categoryID=18
    since sql*plus is not a JDBC thing...
    Oh, and sql*plus can also give you easier access to timing information, with "set timing on".

  • Inventory on Hand Report - Using Union ALL - need two fields to be part of the group

    Hi all,
    I have created an Inventory "on Hand" Report that takes the Current Inventory from the Item Entry table and the Sales from Unposted Sales Line table and Transfers in and out from the Unposted Transfer Line table.  I have joined the tables
    using the UNION ALL function. 
    My problem is that the Transfer table has two locations whereas the other tables only have one.  I am grouping on Location code from the Item Entry table which is equivalent to BOTH Transfer from location and the Transfer to.    
    As an example, there are 15lbs of inventory for Product A in Location #1 with a transfer out of 15 lbs.  The Transfer out is going to Location #2
    I don't know how to write the query or set up the group so that it recognizes both the Transfer to and the Transfer From fields
    I want the report to look similar to the one below but I can only get it to show one of the locations.  Is there some way to use the Union function and have one field in the first table be or equivalent to two fields in another?
    Location   Code
    Item No.
    Lbs
    Sales Orders
    Transfer Out
    Transfer In
    Available   Inventory
    Location #1
    Product A
    15
    -15
    Location #1
    15
    -15
    Location #2
    Product A
    15
    15
    Location #2
    15
    15

    Hi Igor,
    You can get a custom sort order added to your IP column without the need for a second column.
    Consider that the sorting is done strictly left-to-right across a string in the column. The string can be any valid HTML content. So, you could wrap your string within, say, a SPAN tag and add an attribute to that tag that contains the sort order you need before the text that is displayed to the user. As long as the attribute is correctly structured (that is, all instances are of the same length, for example), then sorting will work correctly. For example:
    SELECT
    '<span title="' || PAD_IP_ADDRESS(IP) || '">' || IP || '</span>' Y
    FROM ...Now you need to ensure that the PAD_IP_ADDRESS() function returns the correct values. In IP addresses, you have anything from "0.0.0.0" to "255.255.255.255". To get them to sort "numerically", you need to pad one or two digit numbers to get three digit numbers for each value - so, "0.0.0.0" becomes "000.000.000.000". You could create a function to do this - something like:
    CREATE OR REPLACE FUNCTION PAD_IP_ADDRESS
      pIP IN VARCHAR2
    RETURN VARCHAR2
    IS
      vIP VARCHAR2(15);
      vTEMP APEX_APPLICATION_GLOBAL.VC_ARR2;
      vSEP VARCHAR2(1);
    BEGIN
      vSEP := '';
      vIP := '';
      vTEMP := APEX_UTIL.STRING_TO_TABLE(pIP,'.');
      FOR x IN 1..vTEMP.COUNT
      LOOP
        vIP := vIP || vSEP || TRIM(TO_CHAR(TO_NUMBER(vTEMP(x)),'000'));
        vSEP := '.';
      END LOOP;
      RETURN vIP;
    END;The output from this would look something like:
    &lt;span title="001.001.001.001"&gt;1.1.1.1&lt;/span&gt;
    &lt;span title="002.255.255.255"&gt;2.255.255.255&lt;/span&gt;
    &lt;span title="010.001.199.098"&gt;10.1.199.098&lt;/span&gt;Andy

  • Where() clause returning "The query specified in the URI is not valid..."

    I have a .Net mobile service.
    Calling this:
    https://qserv.azure-mobile.net/tables/items?$filter=(company%20eq%20%27987af3f9-8d44-4a9d-8be2-7e0567287106%27)
    Returns:
    {"message":"The query specified in the URI is not valid. Could not find a property named 'company' on type 'Default.<>f__AnonymousType2_3OfString_String_Double'."}
    The field name in the "items" entity model is "company" and on the database is "company_Id", neither will work.Using http://ajax.aspnetcdn.com/ajax/mobileservices/MobileServices.Web-1.2.5.min.jsWhat is wrong?
    Regards

    I see. Now works. So it would be like doing "SELECT ITEM,CATEGORY,COUNTRY, FROM TABLE WHERE CATEGORY='toy' AND COUNTRY='US'"
    All rows will contain the "CATEGORY" and "COUNTRY" fields (or more), which is kind of redundant and bandwidth consuming.
    Hope MS can change this.
    Regards

  • Where to update the query

    Hi All,
    I am new to webadi. Pls do the needful to resolve my problem. My clinet gave letter names and he told me that, letter are retriving incorrrect results. So, change the query to get the proper details. So, Can anobody suggest what i need to do like where to change the qurery and how to find integrator.?
    Thanks in advance.
    Hasini.

    Hi Mohan,
    First you may want to check if this error is surfaces in other environments as well or this is the only environment where you are seeing this.
    If it does not work only in this environemnt you may want to have a look at the counters table and check if all counter are good.
    also if any of the values are hardcoded you may wnat to check if they conflict with something in the UCM.
    also cehck ther permission of ther service that you are calling.I hope you are calling CHECKIN_UNIVERSAL.
    hope it helps.
    cheers,
    swapnil

  • In the query out put,right click on k.f,there we fine one option HIDE

    why we use it?

    hi,
        it is generally used if you do not want to see the keyfigure in the query output.
    if u wnat to do analysis on sales and you do notyt want to see predouction kf then u can use it
    regards
    pls assign points if helful.

  • Can I have two versions of firefox - latest and the older 3.6, which I can only use with Blackboard?

    My 8 new Firefox is fine. But I am using the Blackboard online LMS, which has not yet been upgraded for the newer Firefox. I was told Blackboard works fine with the 3.6 firefox. Hence I want to know if I can have both versions of firefox at once on my Windows 7 laptop PC. Or can I only have one version at a time.

    Yes - you can either use a portable version of Firefox 3.6 or you can run two profiles. If you search on how to run 2 profiles there are instructions out there.

  • Where are all the System.out.printlns sent to?

    I have log4j running but when this fails to load I rely on System.out's to see what went wrong. I checked the application log for the application in application-deployments/<application-name>/home_default_island_1 directory but it doesn't record the System.out's.
    Regards,
    Anthony

    Thanks Avi,
    However the OC4J Home Page is not always the answer to every question. I don't want to sound ungrateful but OAS has way too much documentation. Granted it has alot of features and operating OAS should not be delegated to a lone developer but I can 't be sifting through documentation looking for a simple answer as "Where do System.out.printlns go to"
    I mean simply put OC4J (running inside OAS) has a local log per application application-deployments/<application-name>/home_default_island_1 which I would expect to be the default location for any System.outs to be. Isn't it just logical thinking? I'm not sure exactly what opmn's relationship with OC4J is but from a developer point of view it's a different entity!?!
    For now I'm still refining our development processes for an upcoming project so it looks like I'll be ditching developer testing on OAS full install to running a local OC4J standalone - too much time is wasted deploying an app for a start and there is no easy access to the remote console logs. Also the System.outs in standalone are easily visible anyway.
    Please understand this is not a formal complaint or grudge but a developers desparate cry to try and get a job done.
    Anthony

  • Condition IF in formula of the query!

    Hi,
    I need to define a Key figure which has values calculated depenidng on the logical expression:
    if GID-PRD<= 2 and PRD-GID<=5 then counter should add 1 or 0 depending upon the condition success.
    now i had written in the formula as follows:
    (GID-PRD<=2) + ( PRD-GID<=5) * count( ).
    but it is saying general syntax error.
    Can any body suggest me whats wrong in what i had coded?
    Thanks,
    Ravi

    Thanks Bhanu,
    It is syntactically correct. but all the results of this KF are 1 irrespective of the condition success.
    i had observed there are more fails than the successes but results are always 1.
    i am missing something here for sure.
    Not sure where
    Thanks,
    Ravi

  • Putting the Header for Text part in the query properties.........

    Hi,
    I am displaying the Key and text for the characteristic.....
    Is it possible that I can put some column heading for the text part...
    Like if I display 0Material (key and text), I can display the column heading for the text part
    as "Material Descripion"
    Is it possible.......? Please let me know
    Thanks , Jeetu

    I dont think it is possible the way you are thinking. However, if you have Material description in the data target (MAKTX) then you can use this in the separate column in the report.
    Thanks..
    Shambhu

Maybe you are looking for

  • Wont boot from cd???

    I have a slot-loading iMac that wont boot from a CD. Does anyone know why? I have tried holding C and choosing the CD as a start-up disk but it doesnt work. The CD i am trying to start-up on is the Mac OS 9 CD. Can anyone help?? Thanks Daniel.

  • Material not maintained in plant P100

    while adding material using MB1C T-Code i m getting bellow error Material "bicycel" not maintained in plant P100 and if i press again getting another message parameter for plant P100 not maintained in inventory management

  • Need clarification: SCJP questions

    The following code when pasted in eclipse is giving a compilation error but the answers are as given below!! Please explain. Question 1 Given: 11. static classA { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B

  • Color to Ouput losing corrections - What am I missing

    I have some footage that is in BlackMagic 10 bit PAL format. I have made the round trip to Color and back to FCP fine. If I try and export it out of FCP I seem to lose all the corrections I did in FCP. Am I missing a switch here? Below are links to s

  • [SOLVED] Removing archiso's UEFI boot failed using xorriso

    I'm trying to remove UEFI boot support of the latest archiso since I have to boot the install CD on my MacBook2,1 (which doesn't support UEFI, only supports 32-bit EFI). I follow this guide but this is the xorriso output:     libburn : SORRY : Neithe