Different conditions for different columns

Hi,
I have two tables and both have 3 common columns. I have to write a query joining the two tables and get different columns with different conditions.
For e.g., I have the tables test and test1.
create table test (a1 varchar(10), a2 varchar(10), a3 varchar(10), a4 date, a5 number, a6 number, a7 number, a8 number);
create table test1 (a1 varchar(10), a2 varchar(10), a3 varchar(10));
insert into test1 values('abc', 'a', 'z');
insert into test1 values('xyz', 'b', 'y');
insert into test values('abc', 'a', 'x', trunc(sysdate,'MM'), 100, 200, 300, 400);
insert into test values('abc', 'b', 'z', trunc(sysdate,'MM'), 567, 4778, 4234, 6767);
insert into test values('xyz', 'a', 'y', trunc(sysdate,'MM'), 5467, 2134, 5678, 8332);
insert into test values('xyz', 'b', 'z', trunc(sysdate,'MM'), 3534, 744, 678547, 46);
insert into test values('abc', 'a', 'x', trunc(add_months(sysdate,-1),'MM'), 700, 800, 900, 600);
insert into test values('abc', 'b', 'z', trunc(add_months(sysdate,-1),'MM'), 565477, 474578, 4456234, 226767);
insert into test values('xyz', 'a', 'y', trunc(add_months(sysdate,-1),'MM'), 235467, 2342134, 255678, 258332);
insert into test values('xyz', 'b', 'z', trunc(add_months(sysdate,-1),'MM'), 324534, 25744, 678547, 78846);
select * from test1;
A1     A2     A3
abc     a     z
xyz     b     y
select * from test;
A1     A2     A3     A4                     A5     A6     A7     A8
abc     a     x     05/01/2010 00:00:00     100     200     300     400
abc     b     z     05/01/2010 00:00:00     567     4,778     4,234     6,767
xyz     a     y     05/01/2010 00:00:00     5,467     2,134     5,678     8,332
xyz     b     z     05/01/2010 00:00:00     3,534     744     678,547     46
abc     a     x     04/01/2010 00:00:00     700     800     900     600
abc     b     z     04/01/2010 00:00:00     565,477     474,578     4,456,234     226,767
xyz     a     y     04/01/2010 00:00:00     235,467     2,342,134     255,678     258,332
xyz     b     z     04/01/2010 00:00:00     324,534     25,744     678,547     78,846I have to write a query to get values for columns a1, a4, a5, a6, a7 and a8. For each distinct month fro mthe column a4, the values for columns a1, a4 a5 and a6 should be based on the condition test1.a1=test.a1 and test1.a2=test.a2. The condition for columns a7 and a8 should be test1.a1=test.a1 and test1.a3=test.a3.
How can I do this?
Thanks,
Machaan

remove the 4th join and only duplicate test;
SQL> ed
Wrote file afiedt.buf
  1  select distinct
  2  case
  3          when t11a1 is null then
  4            t12a1
  5          else
  6            t11a1
  7        end as a1
  8        ,case
  9          when t11a4 is null then
10            t12a4
11          else
12            t11a4
13         end as a4
14        ,case
15          when t11a5 is null then
16            t12a5
17          else
18            t11a5
19         end as a5
20  from (
21        select t11.a1 as t11a1
22              ,t11.a2 as t11a2
23              ,t11.a3 as t11a3
24              ,t11.a4 as t11a4
25              ,t11.a5 as t11a5
26              ,t11.a6 as t11a6
27              ,t11.a7 as t11a7
28              ,t11.a8 as t11a8
29              ,t12.a1 as t12a1
30              ,t12.a2 as t12a2
31              ,t12.a3 as t12a3
32              ,t12.a4 as t12a4
33              ,t12.a5 as t12a5
34              ,t12.a6 as t12a6
35              ,t12.a7 as t12a7
36              ,t12.a8 as t12a8
37        from test1 t1
38            ,test  t11
39            ,test  t12
40        where t1.a1 = t11.a1
41        and   t1.a2 = t11.a2
42        and   t1.a3 = t12.a3
43* )
SQL>
SQL> /
A1         A4                A5
xyz        01-APR-10     324534
xyz        01-MAY-10       3534
abc        01-APR-10        700
abc        01-MAY-10        100

Similar Messages

  • Where condition for a column in BMM

    Hi Gurus,
    I have a requirement where in the BMM(The LTS for this logical table is say 'Fact'), I need a logical column with the following definition.
    count(Dim.status) where Dim.status = ' Accepted' (I didnt add the Dim table to the LTS yet, should I?)
    I know that we can do a count(Dim.status) in the column source . but for the where Dim.status = ' Accepted' part im not sure what to do.
    Should I bring the Dim table as a LTS and define the 'where' condition in the content tab? will that work?
    but what if I have another logical column where I need dim.Status = 'Declined'( we have many more status)
    Plz help

    The suggest statement as Filter(count(Fact.Dollars) Using("dim.status = 'accepted'))
    is based on Answers, this would care about the column is available in Subject Area or not thats it.
    The same kind of functionality can get the using rpd.
    There you might need to map/add (fact source properties and then map using pencil icon on 11g add button in 10g) the dim table to the fact
    so that you can get the expression based on physical columns as
    case when dim.status = 'accepted' then Fact.Dollars else 0 end
    use Aggregate tab for sum;
    Since you are using Fact.Dollars it suppose to be sum, ROW_WIDs go by counts
    Hope this helps :) for more Qs send email
    If helps mark

  • Showing contents of a column based on a condition for another column.

    Hello,
    I am trying to create a report that lists all of the Opportunities within our database. I need a few details about this opportunity to appear. I need the account name that this opportunity belongs to, amongst other things- which I can do, however I also need to show the number of UNITS for this opportunity BUT I have a condition that needs to be met before I show the number of units.
    I only want to show the UNITS IF the PRODUCTTYPE that this opportunity belongs to is "GA". Then I also need another column with UNITS in it, but again I only want the UNITS to appear if the PRODUCTTYPE IS DA.
    Essentially I am trying to find out the number of units per product type and I need these to appear in separate columns. If the PRODUCTTYPE doesn't meet the condition, i.e. the PRODUCTTYPE is not GA then I would like the field to be blank.
    I know that I should write this formula in the "Edit Formula" of the UNITS field, but I do not know how to write this condition.
    I would very much appreciate some help as soon as possible.
    Kind Regards,

    Hi,
    You need to use a case statement, it looks like this:
    CASE
    WHEN opportunity.producttype = 'GA'
    THEN opportunity.units
    ELSE NULL
    END
    Ofcourse you need to use the correct column names.
    Regards, Tim

  • Compare floating points for all columns in parallel

    I have a data set that needs processing and wondering what is the best way to handle.
    What i have:
    1) Text file with 300+ columns (all numbers (float or integers) )
    2) Rows =~ 1M (This is the actual data)
    3) One more text file with 300+ columns (column name same as #1) with boundary conditions for that column (explained below)
    Example: This is content of file1 (cols 300 and rows =1M)
    Col1 Col2 Col3...... Col300
    1.1 4.22 6 8.1234
    1.23 4.5 7
    1.0 4.7 11
    1.3 4.1 13
    2nd File
    ColumName Low High
    Col1 1.0 2.0
    Col2 4.1 4.5
    Col3 5 10
    What i want:
    Compare each column of file 1 with the low/high range of file 2. So if ( col1 < low ) then output=Fail if (col1 > High) output=Fail else PASS if Low < col1 < High
    Output:
    Col1 Col2 Col3
    Pass Pass Pass
    Pass Fail Pass
    Pass Pass Fail
    Question:
    1) I want to do it in parallel since there are million rows and hundreds of column - Need SPEED
    2) I do it in perl right now and it takes about 30-40 mins for this 3GB data file
    3) If there is good way to do it in oracle then i can create 2 tables for these 2 files and write pl/sql function to run in parallel and create output in 3rd table
    a) If this the right way to do.
    b) What would the pl/sql look like and how to run in parallel
    c) Since i will be starting from scratch so open to any new design idea for implementation
    4) Once this is done then i would like to perform other statistics on the first file (MIN,MAX, AVG, MEDIAN etc) and store in different output table
    Appreciate any help.

    However, i will have to check with our DBA but the answer would be no most likely.It would be very interesting to know the reason(s) why your DBA would say no to external tables, so please keep us posted on that.
    He/she can easily create a directory object that points to a specific physical directory on the server, only allowing you access to that directory.
    By simply querying your files, you can use the power of SQL (for example: analytics etc) to do set-based processing, you'll crunch a million rows within a minute.
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:6611962171229
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:5448988086977
    http://www.oracle-developer.net/display.php?id=325
    How will you get your data into your fixed 'playtables' in the first place anyway?
    I use cluster computing so things can be done in parallel but there are too many files to handle.If those files all have an identical layout then the external table can query them all at once.
    You could do this dynamically.

  • XML Report - Conditionally showing a column in between other columns

    I have a XML Report, with columns
    A, B, C, D
    Now I need to add a new column E in between B and C when certain condition is satisfied.
    A, B, E, C, D
    for column E, I kept <?if:column='X'?> columnname <?endif?>.
    When condition is satisfied it is displaying column and also values, but when not an empty column is displayed with no values, I dont want this empty column when condition is not satisfied.
    It should just show A, B, C, D instead of A, B,  , C, D
    Request you to help me with my requirement.

    Hi Kavipriya, thanks for response.
    I tried below condition for that column:
    <?if@column:OM_Due_Date_X='Y'?>  <?OM_Due_Date_L?>  <?end if?> 
    I am setting OM_Due_Date_X in sql package to 'Y' if customer is 'Rob' else it will be 'N'.
    If 'Y', then I am displaying a column name OM Due Date which is <"OM_Due_Date_L?>
    Now for Column values it is just <?OM_Due_Date?>
    Do I need to change anything here ?

  • Displaying different colors for cells/columns in Interactive Report

    Hi,
    I have a requirement to display just the 'cells' in the Interactive Report columns with different colors.
    There are 3 columns in the Interactive report.
    The color coding for all the 3 different columns should be such that:
    <40% - red color
    40-70-orange
    greater than 70%-green
    I tried the highlight option in the report and saved the report as default, but still the color condition ended up getting displayed to the end user. I dont want this.
    Can someone suggest a better way to handle this requirement?

    Perhaps explore similar solutions described here
    Background Colour of Report Cell Issues.
    Scott

  • Design a single template for multiple reports with different column order

    Hi,
    I need to migrate the existing reports from SQL Server Reporting Services to Crystal Report 2008, and the column order in the report is very important to the clients since clients have existing code to ingest these reports into their database. Now I want to create a single template with lot of parameters for all reports. My question is how I might use one template to create multiple reports with different column orders in the reports?
    For example, client A has the following column order in their report: firstName, LastName, DateBirth, SSN. Client B has the following column order in their report: SSN, DateBirth, LastName, FirstName. Can I use one template to create these multiple reports?
    Thanks in advance.

    -As I mentioned you can find Template Field object in Insert menu of crystal report Designer 2008.
    As soon as you select Template Field object you will be able to see a box beside ur mouse cursor. Drag and drop this box at required place. Now when you place this object in report you will get some thing like this "<TemplateField1>" listed under Formula Fields tree. Double click "<TemplateField1>" formula to add your conditions.
    -I have not tested it for large amount of Customers. However as the number of customer increases the number of conditions will get increased.
    For the customer that want the same ordering of columns you can put those customers under one condition.
        for Example...
              if(?Client in ['clientA','clientA']) then
                        <TableName>.<Field>......
    -What do you mean be 40 columns? Do you mean 40 fields or you want to show 40 columns in report? Please elaborate.
    Regards,
    Amrita
    Edited by: Amrita Singh on May 21, 2009 7:54 AM

  • Setting different Tabel Cell SemanticColor for Multiple Columns of each row

    Hi,
    I have requirement of setting different colors to different columns for each row based on some condition in table data.
    The data to table is coming from model, hence table is mapped to model node and attributes.
    I have created Seperate Node CellColorNode with attribue CellClr1 and CellClr2 of type TextView Semantic Color.
    Set the calculated, read only attribute to True. Mapped table columns text view to the CellColorNode->CellClr1 and CellColorNode-->CellClr2 correspondingly.
    Now, my query is how do i set the colors to CellClr1 and CellClr2 attributes. As I need to set the color for multiple columns of each table row.
    Is it in method getColorCellCellClr generated? Any  Example Code?

    Its resolved by following below link
    http://scn.sap.com/thread/158286

  • BO xi 3.1 u2013 schedule a template for multiple reports with different column

    Hi,
    I need to migrate the existing reports from SQL Server Reporting Services to BO, and the column order in the report is very important to the clients since clients have existing code to ingest these reports into their database. Now I want to schedule a single template with different parameters for all reports in BO, or create a single template with lot of parameters for all reports. My question is how I might use one template to create multiple reports with different column orders in the reports?
    For example, client A has the following column order in their report: firstName, LastName, DateBirth, SSN. Client B has the following column order in their report: SSN, DateBirth, LastName, FirstName. Can I use one template to create these multiple reports?
    Thanks!

    Hi,
    The only approach I can think of is to create a template report which uses variables
    For each column you would need to variable
    v_columnAName and v_columnAValue
    v_columnAName would have a if statement in it
    =if([client]="clientA" or [client]="clientC";NameOf([firstName]);if([client]="clientB";NameOf([SSN]);NameOf([lastName]));
    v_columnA would have a if statement in it
    =if([client]="clientA" or [client]="clientC";[firstName];if([client]="clientB";[SSN],[lastName]));
    This would only work when you had a small set of clients.
    This might be more managable if it was done in the universe
    Regards
    Alan

  • Different number of rows for different columns in JTable

    hi
    I need to create a JTable with different number of rows for different columns...
    Also the rowheight should be different in each column...
    say there is a JTable with 2 columns... Col1 having 5 rows and column 2 having 2 rows...
    The rowHeight in Col2 should be an integer multiple of Rowheight in Col1
    how do I do this ??
    can anybody send me some sample code ?????
    thanx in advance

    How about nesting JTables with 1 row and many columns in a JTable with 1 column and many rows.
    Or you could leave the extra columns null/blank.
    You could use a GridBagLayout and put a panel in each group of cells and not use JTable at all.
    It would help if you were more specific about how you wanted it to appear and behave.

  • Bapi or FM to Create Or Update multidimensional freight conditions for different scale id for different conditions

    Hello all,
    I want to create or update multidimensional freight conditions for different scale id for different conditions.
    I cound not find any Bapi or FM for this. I uesd BDC for this but i can not rely on it.
    If any one have other solution than IDOC then suggest me.
    Any BAPI or FM available then suggest me.

    Hi Gowri Rao,
    Can you please tell me, what values do you pass in table 'IT_PRICING_CONDITIONS'?
    Regards,
    Pratik

  • Different column views for different mailboxes?

    Is it possible to view different columns for different mailboxes?
    Normally, the "Sent" mailbox displays only "To," not "From;" and the other mailboxes display only "From" and not "To." That's fine. But I have another mailbox I've created where I've stored old sent mail, and I only want to see the "To" column, not the "From" column in that mailbox. When I select that mailbox and then choose View-Columns, whatever I choose is applied to the "In" box, and all the other mailboxes (except "Sent" )... is there another way to do this?
    G3 B&W   Mac OS X (10.3.9)  

    Column view settings are stored globally for all mailboxes. You cannot change them for one mailbox without also affecting the rest, except Mail allows you to have slightly different From/To and Date Sent/Date Received settings for Sent.

  • Are different conditions for deleting applets possible?

    Is it possible to set different conditions for applet deleting?
    So someone can delete, for example, applet_A and applet_B but can not delete applet_D. While applet_D can not be deleted at all or can be deleted by someone else who can fulfil conditions for applet_D deletion.
    What is way to do so?
    PS and offtopic: why "applet N", where N - character between 'B' and 'D', is so magic so i can not post message with this phrase? The forum engine writes something like - "this content is not allowed", heh.
    Edited by: 666 on Feb 27, 2011 9:32 AM

    666 wrote:
    Is it possible to set different conditions for applet deleting?
    So someone can delete, for example, applet_A and applet_B but can not delete applet_D. While applet_D can not be deleted at all or can be deleted by someone else who can fulfil conditions for applet_D deletion.
    What is way to do so?
    PS and offtopic: why "applet N", where N - character between 'B' and 'D', is so magic so i can not post message with this phrase? The forum engine writes something like - "this content is not allowed", heh.Do you mean
    | applet&#67; | ( applet &amp;#67; ) |
    | applet_&#67; | ( applet_&amp;#67; ) |

  • Trying to get different column headings for folders in Apple Mail - Help!

    Hi there
    I really hope someone can help here.
    I have a few different email accounts coming into my Apple Mail program. For each account I am using a 'Saved' folder (for the incoming email i have read) and a 'Sent' folder (for the emails I have sent).
    In my 'Saved' folder, I want my column headings to be:
    a. Who the email is from
    b. The subject line
    c. The date and time received
    In my 'Sent' folder, I want my column headings to be:
    a. The address I have sent to
    b. The subject line
    c. The date and time received
    The problem is that when I changed the column headings for one folder, it changes them for all of them. So I can display who my incoming emails are from, but in the sent folder, it only tells me who my sent emails are from....me!! This is no use at all. Is there anyway to apply different column headings to different folders? In Entourage this is easy, but Im at a loss of what to do in mail.
    Please help if you can
    Many thanks
    Dan

    as i said, Sent mailbox is special and can have custom columns separate from other mailboxes. ALL other mailboxes have the same columns and you can only customize them simultaneously. if you want to change that leave Apple feedback on the issue
    http://www.apple.com/feedback/macosx.html

  • Matrix with different dimensions for each column

    Hi,
    I would like to have a matrix with different dimensions (rows) for each
    column, for example, I want the first column has 3 rows, the second one
    5 rows, the third one 10 rows, and so on.....
    With a simple array it is not possible, and then I make an array (for
    my columns) of clusters and each cluster has another array (rows for
    that column). Is it the best way to do it? Is it correct?
    Thanks,
    ToNi.

    Yes, everything we told you in this old thread  is still true!
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for