Getting data of two records in one line using SQL

Hi,
We have a COMPANY_RESEARCH table that maps companies to the Research Universes that do research on them. This table has:
COMPANY_ID VARCHAR2(100), foreign key to COMPANY table.
RESEARCH_UNIT_ID CHAR(1)
Valid values for RESEARCH_UNIT_ID are 1(US Equity), 2(Canadian Equity) and 3(Debt security).
Within my COMPANY_RESEARCH_ID table, I have:
COMPANY_ID RESEARCH_UNIT_ID
aaaa 2
aaaa 3
How can I write a SQL query that gives me the output?
Company Id Equity Debt
aaaa Canada Yes
My attempt was as below:
select
     FILTERED_COMPANIES.COMPANY_ID as Company,
     DECODE(FILTERED_COMPANIES.RESEARCH_UNIT_ID,'1','US','2','Canada','3','N/A') As Equity,
     DECODE(FILTERED_COMPANIES_1.RESEARCH_UNIT_ID,'1','N/A','2','N/A','3','Yes') as Debt
FROM
          select distinct
          company_id, research_unit_id
          from company_research_relation
     )FILTERED_COMPANIES,
          select distinct
          company_id, research_unit_id
          from company_research_relation
     )FILTERED_COMPANIES_1
WHERE
     FILTERED_COMPANIES.COMPANY_ID = FILTERED_COMPANIES_1.COMPANY_ID
     AND FILTERED_COMPANIES.RESEARCH_UNIT_ID = FILTERED_COMPANIES_1.RESEARCH_UNIT_ID
but that produces output as below:
Company Id Equity Debt
aaaa Canada N/A
aaaa N/A Yes
Thanks in advance..

Hi,
how about this one?
SELECT select_equity.company_id, enquity, dept, select_equity.research_unit_id, SELECT_dept.research_unit_id
FROM
(SELECT company_id, research_unit_id, DECODE(RESEARCH_UNIT_ID,'1','US','2','Canada','3','N/A') enquity FROM company_research) select_equity,
(select company_id, research_unit_id, DECODE(RESEARCH_UNIT_ID,'1','N/A','2','N/A','3','Yes') Dept FROM company_research) SELECT_dept
WHERE select_equity.company_id = SELECT_dept.company_id
AND enquity != 'N/A'
AND dept != 'N/A';
Regards,
Gerd

Similar Messages

  • Getting data of two columns in one column

    Hi,
    I need to show data of two columns in one column, I also want to insert space between the data of both the columns in the output
    can i use something like this ?
    (IMPORTER_NAME+' '+IMPORTER_ADDRESS) as "Location"

    872435 wrote:
    Hi,
    I need to show data of two columns in one column, I also want to insert space between the data of both the columns in the output
    can i use something like this ?
    (IMPORTER_NAME+' '+IMPORTER_ADDRESS) as "Location"You can either use the CONCAT function or || -
    SQL> select 'Hello'||' '||'World', CONCAT(CONCAT('Hello',' '),'World') from dual;
    'HELLO'||'' CONCAT(CONC
    Hello World Hello WorldHTH
    David

  • SaveToFile example modificati​on to get data from two channels simultaneo​usly.

    We are trying to modify the “SaveToFile” example for C++. This particular example comes with NI-scope 2.9.1 and some other versions. This example collects data from one channel and saves the output as a text file. Also, we are using NI PCI-5112 DAQ.
    However, it can be modified to get data from channel 0 and channel 1 at the same time. There is a help file called “Fetching Multiple-Record Acquisitions”, which is under the NI-High speed digitizer help topics. This confirms that you can modify the code to get data from two channels and the output will be a text file where every other value is from one channel. This help file also gives some code. However, it is not very much helpful to us, please keep in mind that we have only taken a basic course in C++.
    Our project is to analyze the data, however, we need to acquire the data before we can analyze. We have spent so much time trying to get the data.  What we need to do is get data from both channels simultaneously and output the data as a text file.
    Can anyone help us to modify the code so it can get data from both channels simultaneously? Or can anyone help as where we can get more information? Or does anyone know of any sample examples that will take data from two channels simultaneously and output the data as a text file or any other type of document.
    Any help will be really appreciated, as we have spent so much time trying to acquire the data.
    Thanks.

    Hi Finomad,
    Please see this post for an answer to your question.
    Regards,
    Natasa

  • Combine values from two records in one query

    Hello.
    Is it possible to combine two record - only one column value?
    With one query we get these results:
    A____B____C____D____E_______F_______G______H
    +++++++++++++++++++++++++++++++++++++++++
    28___84___P___16____________1____02.06.09___1
    28___84___p___8_____________1____02.06.09___1
    28___84___S___16____________1____02.06.09___1
    28___84___T___12____________1____02.06.09___1
    28___84___1___137___________1____02.06.09___1
    28___84___5___18___66,42____1____02.06.09____1
    28___84___6___14____________1____02.06.09___1
    28___84___8___17___214,2____1____02.06.09___1
    If there is a record with column C value 'p', then column value 'D' should be added to record with C value 'P' and 'S': result should be like this:
    No 'p' record and values (D column) for 'P' and 'S' should be a summed by 8 from record 'p'.
    A____B____C____D____E_______F_______G______H
    +++++++++++++++++++++++++++++++++++++++++
    28___84___P___24____________1____02.06.09___1
    28___84___S___24____________1____02.06.09___1
    28___84___T___12____________1____02.06.09___1
    28___84___1___137___________1____02.06.09___1
    28___84___5___18___66,42____1____02.06.09____1
    28___84___6___14____________1____02.06.09___1
    28___84___8___17___214,2____1____02.06.09___1
    And this should be restricted to column A value.
    Any idea?
    Thanks.
    Edited by: DejanH on Jun 2, 2009 11:39 AM

    OK, that's a messy requirement, here's one for 'p' but no 'P' (and 't' but no 'T'), and you can expand that for others yourself.
    WITH test_data AS (
    SELECT 28 A, 84 B, 'p' C, 8 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
    SELECT 28 A, 84 B, 'S' C, 16 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
    SELECT 28 A, 84 B, 'T' C, 12 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
    SELECT 28 A, 84 B, '1' C, 137 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
    SELECT 28 A, 84 B, '5' C, 18 D, 66.42 E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
    SELECT 28 A, 84 B, '6' C, 14 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
    SELECT 28 A, 84 B, '8' C, 17 D, 214.2 E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL)
    -- end test data
    SELECT td1.A, td1.B, td1.C,
         CASE WHEN td1.C IN ('P', 'S') THEN NVL(td1.D,0) + NVL(td2.D, 0) ELSE td1.D END D,
         TO_CHAR(td1.E * 100, 'fm99990,09') E, td1.F, td1.G, td1.H
       FROM test_data td1
       LEFT JOIN (
      SELECT A, SUM(D) D
         FROM test_data
        WHERE C= 'p'
        GROUP BY A) td2
        ON (td1.A = td2.A)
    WHERE C != 'p'
    GROUP BY td1.A, td1.B, td1.C, CASE WHEN td1.C IN ('P', 'S') THEN NVL(td1.D,0) + NVL(td2.D, 0) ELSE td1.D END, TO_CHAR(td1.E * 100, 'fm99990,09'), td1.F, td1.G, td1.H
    UNION
    SELECT td1.A, td1.B, UPPER(td1.C) C,
         SUM(td1.D) D,
         TO_CHAR(td1.E * 100, 'fm99990,09') E, td1.F, td1.G, td1.H
       FROM test_data td1
      WHERE td1.C in ('p', 't')
    GROUP BY td1.A, td1.B, UPPER(td1.C),TO_CHAR(td1.E * 100, 'fm99990,09'), td1.F, td1.G, td1.H
    ORDER BY 1
             A          B C          D E                  F G                  H
            28         84 1        137                    1 02-JUN-09          1
            28         84 5         18 66,42              1 02-JUN-09          1
            28         84 6         14                    1 02-JUN-09          1
            28         84 8         17 214,20             1 02-JUN-09          1
            28         84 P          8                    1 02-JUN-09          1
            28         84 S         24                    1 02-JUN-09          1
            28         84 T         12                    1 02-JUN-09          1
    7 rows selected.

  • Get data from two databases?

    Hello all,
    Do anyone know if it's posible to get data from two databases while I'm running SBO in one of them? I need this because our client wants to be able to print reports with all the information stored in both companies. I searched this forum trying to find if this is possible but I did't find any information about this.
    Can someone help me?
    Thanks and regards,
    Mariana Mazzero

    Hi Mariana,
    What you can do is use two company objects to retrieve the data. As far as I know you're not restricted to one company connection.
    You can also just use a standard read only connection (like ADO/ODBC) to retrieve the data for the reports.
    Hope it helps,
    Adele

  • Get value of two fields into one field

    Hellou,
    i need little help with javascript again
    Currently i'm using code below to get value from one field to other:
    getField("Text35").value = getField("Text1").valueAsString;
    Now i'm wondering how to change this code, so i could get values from two fields into one. For example i have field "firstname" and field "lastname", now i want to show this in field "name".
    Example, if field firstname have value John and field lastname value is Doe, i want to show it in field name like "John Doe".
    I hope that u understood what i want
    Thanks for helping me!

    getField("Text35").value = getField("Text1").valueAsString + " " +
    getField("Text2").valueAsString;

  • Can I sync two computers when one is using lion and the other snow leopard

    can I sync two computers when one is using lion and the other snow leopard

    will my data be shared well using Mobile Me?

  • I have two apple ids one I use everyday an one that's old I need the password an Apple ID from it I don't remember any of it anymore an I didn't have an email at the time so I used a friends email address to activate the id an he passed away so now Stuck

    I have two apple ids one I use everyday an one that's old I need the password an Apple ID from it I don't remember any of it anymore an I didn't have an email at the time so I used a friends email address to activate the id an he passed away so now Stuck

    Hi St3vish,
    Welcome to the Support Communities!
    Our Apple ID Account Security Team may be able to help you with this:
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    I hope this information helps ....
    - Judy

  • Scenario is HTTP to db. In HTTP client, when Sender is Business Component, Pi is getting data successfully but when Business system is used as sender Pi is not getting any message in sxi monitor. Please help

    Scenario is HTTP to db. In HTTP client, when Sender is Business Component, Pi is getting data successfully but when Business system is used as sender Pi is not getting any message in sxi monitor. Please help

    Hi Ankita,
    Try to trace at ICM level, Go to smicm transaction
    Set level to 3.
    Later send your request. Finally trace the request in:
    When you have seen the log, check if any exception is raised with your request or the request and share it here.
    Regards.

  • Combine the data of two DSOs into one

    Hello experts,
    how to load the data of two DSOs into a single one using transformations and DTPs?
    Example:
    DSO A keyfields: X,Y,Z / attributes M,N,O
    DSO B keyfields: X,Y,Z / attributes P,Q
    DSO C keyfields: X,Y,Z / attributes M,N,O,P,Q  (result should be a single data record!)
    In the transformation between DSO A and C I map all keyfields and attributes M,N,O (no mapping for P and Q, meaning no transformation rule). For B to C mapping is all keyfields and attributes P, Q (no mapping for M,N,O, no transformation rule).
    When I now load the data of DSO A and DSO B to DSO C I either see the attributes M,N,O or P,Q. This means that only the latest DTP is available and overwrites the attributes with blank values of the first DTP.
    I have a solution using ABAP coding but according to the SAP Training courses (BW330) it should work without using ABAP coding.
    Any help is highly appreciated.
    Thanks in advance.
    Marco

    Hi Marco,
    Thanks again
    I looked into BW330 Business information warehouse - Modelling.
    Course version : 2006 Q2
    Material number : 50079531
    I looked into the page 281 still no luck.
    just an overview i need to create X,Y,Z,M,N,O as info objects characteristics
    and P, O  as infoobjects keyfigure.
    None of them will have attributes and i load XYZMNO to DSO1 and same XYZPO to DSO2.
    Then map DSO1 - DSO3 and  DSO2 - DSO3 and carry out the steps to get the data from DSO1 and DSO2 to DSO3.
    Am i right.
    Regards,
    Harish

  • Unexpected results getting data from two fact tables through conformed dim

    Hi all,
    We are getting an unexpected behaviour in our OBIEE 10.1.3.3.3. We have this scenario:
    We have {color:#0000ff}2 fact tables{color}{color:#000000} called F1 and F2. F1 has one measure, f1m1 and F2 has another one, f2m1.
    We have {color:#0000ff}4 conformed dimensions{color}, called D1, D2, D3, Date.
    When we are requesting for individual fact tables, we are getting:
    date d1 d2 d3 f1m1
    dt1 - x - y - z - m1
    dt1 - x - y - z' - m2
    date d1 d2 d3 f2m1
    dt1 - x - y - z - m3
    dt1 - x - y - z'' - m4
    But, trying to obtain a compare scenario, we are getting
    date d1 d2 d3 f1m1 f2m1
    dt1 x y z m1 m4
    Instead of
    date d1 d2 d3 f1m1 f2m1
    dt1 x y z m1 m3
    Looking at query log, we have catched the reason. That's why BI Server is using to solve this request using ROW_COUNT() to join SAWITH0 and SAWITH1 in SAWITH2 result set. So, the order may not be the same in the results sets in every fact table. More or less, generated query is like:
    WITH
    SAWITH0 AS
    (select ....
    from F1),
    SAWITH1 AS
    (select ...
    from F2),
    SAWITH2 AS
    select from (select ...
    ROW_NUMBER() OVER PARTITION (....) c10
    from SAWITH0.d1 full outer join SAWITH1.d1 ....) D1
    {color:#ff0000}where (D1.c10 = 1){color}
    select SAWITH2. ....
    from SAWITH2
    order by c1..c10
    The problems seems to be that BI server is ordering the result sets SAWITH0 and SAWITH1 and getting row number to join this results sets, but this is not getting the correct result.
    Any ideas?
    TIA
    Javier
    {color}
    Edited by: jirazazábal on Mar 13, 2009 2:46 PM

    I have done a logical fact table with two fact table source on it.
    The Sql performed against the database was this one.
    -------------------- Sending query to database named PRODS_AIX (id: <<153418>>):
    WITH
    SAWITH0 AS (select sum(T21296.CONSUMERS_SALES_EURO) as c1,
         T21309.DIVISION_CODE as c2
    from
         DIVISION T21309,
         C_CONSUMERS_SALES T21296
    where  ( T21296.DIVISION = T21309.DIMENSION_KEY )
    group by T21309.DIVISION_CODE),
    SAWITH1 AS (select sum(T21356.ORDER_VALUE) as c1,
         T21309.DIVISION_CODE as c2
    from
         DIVISION T21309,
         DWH_SALES_ORDER_OVERVIEW T21356
    where  ( T21309.DIMENSION_KEY = T21356.DIVISION_KEY )
    group by T21309.DIVISION_CODE)
    select distinct case  when SAWITH0.c2 is not null then SAWITH0.c2 when SAWITH1.c2 is not null then SAWITH1.c2 end  as c1,
         SAWITH0.c1 as c2,
         SAWITH1.c1 as c3
    from
         SAWITH0 full outer join SAWITH1 On nvl(SAWITH0.c2 , 'q') = nvl(SAWITH1.c2 , 'q') and nvl(SAWITH0.c2 , 'z') = nvl(SAWITH1.c2 , 'z')
    order by c1As you can see one select (SAWITH0) for the first fact table C_CONSUMERS_SALES and one select for the second fact table DWH_SALES_ORDER_OVERVIEW (SAWITH1 ) and the two statement are joined with a full outer join.
    I ask me why you have the three select (SAWITH0,SAWITH1 and SAWITH2). Can you please paste the complete SQL performed ?
    Can you tell us also which SQL is performed if you select only the columns from one fact table and not for the other ?
    Regards
    Nico
    http://gerardnico.com

  • Not getting data for Null Records.

    Hi all,
    I am trying to fetch the records where  sczuo  values are NULL . 
    DATA : BEGIN OF itab OCCURS 0.
    INCLUDE STRUCTURE makz.
    DATA : END OF itab.
    SELECT * FROM makz INTO TABLE itab WHERE sczuo IS NULL.
    IF sy-subrc EQ 0.
      LOOP AT itab.
        WRITE : /3 itab-matnr , 20 itab-sczuo.
      ENDLOOP.
    ENDIF.
    I did not getting data any data .But if i write select statement like this
    SELECT * FROM makz INTO TABLE itab WHERE sczuo = ' '.
    This select statement returns the correct data.
    why my first select statement is not working ? how can i use IS NULL?
    Thanks in Advance,
    Madhu

    Hi,
    When we insert a new field to an existing table, NULL values are automatically inserted into the new field by the system for all existing records. However NULL and SPACE are not the same. 
    The logical expression SQL condition is either "true, false, or unknown". The expression is UNKNOWN if one of the columns involved in the database contains a NULL value and such records could be retrieved by using u201CIS NULLu201D instead of SPACE. 
    Please note that the NULL value is inserted only for the existing records, by the time the new field is being inserted. For all new records, SPACE or the initial (default) value is inserted. 
    If the new field is inserted by checking the checkbox u201Cinitial valuesu201D, then the initial values (SPACE in case of characters) are automatically inserted and not the NULL values.
    ihope u get the solution...
    Thanks
    Ashu

  • Write fields from two tables in one line??

    Hi friends,
    I want to write some fields from bkpf and bseg in one line...
    My report should like something like this:
    ****some text*****
    *for first document*******  bkpf-bldat  kunnr  bseg-belnr    bseg-gsber   bseg-wrbtr     
    *for second document***  bkpf-bldat  kunnr  bseg-belnr    bseg-gsber   bseg-wrbtr     
    *for third document******  bkpf-bldat  kunnr  bseg-belnr    bseg-gsber   bseg-wrbtr  
    etc.
    What should I change in order to get this form in report output?? Can I put these fields in some table so that it looks like excel table??Could you please check out the code below?
      loop at it_bkpf into wa_bkpf.
      loop at it_bseg into wa_bseg.
      write: wa_bseg-gsber, wa_bseg-belnr, wa_bseg-wrbtr.
      endloop.
      write: wa_bkpf-bldat.
      read table it_bsid with key bukrs = wa_bkpf-bukrs
      belnr = wa_bkpf-belnr
      gjahr = wa_bkpf-gjahr
      cpudt = wa_bkpf-cpudt.
      if sy-subrc = 0.
      write: it_bsid-kunnr.
      endif.
      endloop.
    Thanks,
    Nihad

    hi nihad,
    define positions on where to write data like this.
    LOOP AT it_bkpf INTO wa_bkpf.
      LOOP AT it_bseg INTO wa_bseg WHERE belnr EQ wa_bkpf-belnr.
        WRITE: /5 wa_bkpf-bldat.
        READ TABLE it_bsid
        WITH KEY bukrs = wa_bkpf-bukrs
                         belnr = wa_bkpf-belnr
                         gjahr = wa_bkpf-gjahr
                         cpudt = wa_bkpf-cpudt.
        IF sy-subrc EQ 0.
           WRITE: 20 it_bsid-kunnr.
        ENDIF.
        WRITE: 35 it_bseg-belnr,
                    50 it_bseg-gsber,
                    60 it_bseg-wrbtr.
      ENDLOOP.
    ENDLOOP.
    regards,
    Peter

  • Screen painter space between two element in one line

    Hi Experts,
    i am developing a RF program with screens of size 16linesX20columns. limited space should be used . But when i create more than one element in one line , one space is always present between two elements,and the space can not be deleted or overlaped. because of this, elements can not get enought columns.
    i am sure that elements can be adjacent without space in the past time. i am not sure space appear after what changes was done by me...
    can you please give some suggestion if you also have the same issue.
    Yimeng

    Hi,
    Can you elaborate which screen elements are you using.
    You can place screen elements one after another in a single line without any spaces.
    Danish.
    Edited by: Danish2285 on Sep 21, 2011 12:38 PM

  • Get data from two partitions

    I want to do a query that returns data only from last two partitions
    I have this select that returns data from one partition only.
    select *
    from tsieven PARTITION(P200707_2Q)
    I would like to have something like this for example...
    select *
    from tsieven PARTITION(P200707_2Q and P200707_1Q)

    Oracle version is 9i
    Partition method (MAX VALUE): TO_DATE(' 2006-04-16 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    Usually the partition is divided by 15 days. starts in the begin of the month and ends in 15th of the same month.
    Partition column: DATA_CRIACAO
    I'm trying to to this query:
    select tsieven.loptica, tsieven.data_evento Data_Distribuicao
    from tsieven (PARTITION MAX), tgirnos n, tsiobje o
    where tsieven.no_evento = n.COD_NO
    and tsieven.loptica = o.loptica
    and to_char(tsieven.data_evento,'dd-mm-yyyy') = to_char(p_data,'dd-mm-yyyy')
    and o.cod_classe = p_classe
    and n.COD_TIPO_NO='2'
    and tsieven.COD_T_EVEN = 'EMZ'
    and n.cod_no = p_cdp
    order by tsieven.loptica
    For example I need to get data for sysdate from 27th of july it's not in this last partition, because it started a new one in 1st of august.
    Hope I'm being clear now.
    Thanks for your help.

Maybe you are looking for

  • Getting FRM-40010 Error While opening new form  .fmx

    Hi, Oracle apps : 11.5.10.2 Forms : Forms 6.0 I'm creating a custom form by using one oracle apps table.I created a basic form by using template.fmb and then saved it to directory "/dir1" and run this form by connecting to oracle apps database. When

  • Disk Repair Error (Time Machine Partition)

    For the second time, my Time Machine backup partition reports errors when I try to mount it (exists on my external hard drive via USB). As soon as I plug in the USB external, I get this error: *Disk Repair* The disk "Backup" was not repairable by thi

  • Noise issue when not playing

    I did a AE cs 5.5 project in 8 bpc mode into premiere cs 6 when I'm not playing the video I see noise in the video (See photo 1) when play the video it looks good. I also included a snapshot of my video card info which I'm using on a Z800 with 24 gig

  • Easily identify Exchange Invites?

    I have switched over to using Mail in Snow Leopard with my companies Exchange 2007 server from Entourage. Overall I am MUCH happier, but there are a few things I am still trying to work out. One of them is how to easily identify meeting invites. When

  • Analyze Speech no text

    Does anyone know where the text for the analyzed speech is located?  I have analyzed the speech with encoder and afterwards I don't see anything in premier or encoder.  Additionally, I have loaded US English speech file from Adobe site.