Want to fetch two rows values into a single sql result

Let me first explain the situation first
I am having two tables
1. Animal_details(animal_id,and other details)
2. Animal_weight(animal_id,seq_no,weight,date_weighed)
here actually situation is that for each weight I am inserting a new row with seq_no say
1 for first weight
2 for second weight ....
with their weight and date
eg. animal_id = 1, seq_no = 1, weight = 200, date_weighed = 12-may-2000;
animal_id = 1, seq_no = 2, weight = 250, date_weighed = 12-june-2000;
means seq_no = 1 represents 1st weight of animals
seq_no = 2 represents 2nd weight of the animals
like this an animal can have any no. of times weighted.
now what I want is that I want to show a result with
animal_id,weight_1,weight_2 with other animal details in a single row
how can I have both first weight and the second or more weights in same row for any animal?
Please Reply soon, Its urgent.
Thanks

You can't issue an SQL with 100% dynamic column list. What you can do is issues something like:
with t as (
           select  animal_id,
                   max(case seq_no = 1 then weight end) first_weight,
                   max(case seq_no = 2 then weight end) second_weight,
                   max(case seq_no = 3 then weight end) third_weight
             from  animal _weight
             where seq_no <= 3
             group by animal_id
select  t1.animal_id,
        first_weight,
        second_weight,
        third_weight,
        other_details
  from  t t1,
        animal_details t2
  where t2.animal_id = t1.animal_id
/SY.

Similar Messages

  • How to SUM two count(*) values in a single sql tatement?

    How can I get a single SQL statement to sum two values from a count(*)
    I want something like this:
    SELECT COUNT(*) FROM MYTABLE
    UNION
    SELECT COUNT(*) FROM MYOTHERTABLE;
    but instead of getting
    111
    222
    I want to see the sum of the two values.
    333can such a thing be done with one statement. I know I can do stuff inside a BEGIN END and have vars but wonder if there is simple single statement solution.
    Thanks in advance,
    David Miller

    SQL> select count(*) from user_indexes;
                COUNT(*)
                      30
    SQL> select count(*) from user_tables;
                COUNT(*)
                      43
    SQL> select (select count(*) from user_indexes) + (select count(*) from user_tables)
      2  from dual;
    (SELECTCOUNT(*)FROMUSER_INDEXES)+(SELECTCOUNT(*)FROMUSER_TABLES)
                                                                  73

  • Concatenate multiple row values into single column value

    Hello,
    Can anyone please refresh my memory on how to concatenate multiple row values into a single column value.
    In the following query, I will get multiple denial reasons per application and I would rather return all denial reasons on one line.
    SELECT a.application_id, a.membership_number,
    r.reason_text AS denial_reason,
    a.appl_receipt_date AS application_receipt_date,
    a.plan_request_1 AS application_plan_code,
    a.adjudication_date AS application_denial_date
    FROM application a, PLAN p, application_reason ar, reason r
    WHERE a.plan_request_1 = p.plan_cd
    AND a.application_id = ar.application_id
    AND ar.reason_id = r.reason_id
    AND a.adjudication_cd = 'D'
    AND a.appl_receipt_date BETWEEN '01-jan-2006' AND '31-dec-2006'
    AND p.plan_type_id = 12 and a.application_id = :appId
    ORDER BY application_id
    Any help is greatly appreciated.
    Thanks,
    -Christine

    found the following
    SELECT deptno,
           LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
           KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT deptno,
                   ename,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
            FROM   emp)
    GROUP BY deptno
    CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
    START WITH curr = 1;
        DEPTNO EMPLOYEES
            10 CLARK,KING,MILLER
            20 ADAMS,FORD,JONES,SCOTT,SMITH
            30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
    3 rows selected.at http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php

  • I want to spit cell the value into two separate columns like f_name & l_nam

    Hi Guys,
    I have excel data in one cell with ',' separated data.
    sample data:
    empno ename
    121 ravi,kann
    232 ram,raman
    here ename value in one provided in one cell.
    Now i want to spit cell the value into two separate columns like first_name and last_name?
    Thanks in advance
    -LK

    with sample_data as
      select 121 empno, 'ravi,kann' ename from dual union all
      select 232 empno, 'ram,raman' from dual
    select empno,
           substr(ename,1,instr(ename,',')-1) first_name,
           substr(ename,instr(ename,',')+1) last_name
    from sample_data;       or with regular expressions:
    with sample_data as
      select 121 empno, 'ravi,kann' ename from dual union all
      select 232 empno, 'ram,raman' from dual
    select empno,
           regexp_substr(ename,'^[^,]*') first_name,
           regexp_substr(ename,'[^,]*$') last_name
    from sample_data; Edited by: hm on 04.07.2012 06:22

  • Addition of two rows values in table  using formatted search

    hi all,
            i have created one UDF field in market document rows, now in AR invoice i need to add the values in the UDF fields of two rows, want to show it in anather outside UDF in title. kindly suggest me some query to track that.
    Ex:- i had entered two items in rows and
    for first UDF row i have given 20
    for second UDF row i have given 30.
    now i need to show sum of the two UDF in two rows in title UDF.
    kindly give me some query used for formatted search to do this task.
    regards
    sandip

    Sandip,
    To the best of myknowledge When you try to take the row value to the header the results of the Formatted Search are not consistent.
    but for your interest, I am giving below the logic to work this out.
    You need two Header level user fields.  One to copy the row user fields value and the other to store the sum.
    You can create a simple SQL "SELECT $[$38.U_UserFieldName] (substitute with row level user field name) and attach it to the first header level user field and make it Auto refresh on doc total.
    Then Attached SQL  "SELECT $[ORDR.U_HeaderUserField1] + $[ORDR.U_HeaderUserField2]"
    The results could be flaky because the header user field takes the value of the active row and sometime it only considers the first row active though you might be entering the second row of data.
    My recommendation would be to Use The Transaction Notification Stored Procedure for this by which you can be absolutely sure that the Header User field will have the sum.
    Let me know if you need directions for this.
    Regards
    Suda

  • How to prevent from inserting two similar values into DB?

    Hi,
    I wanted to know how we can prevent from inseting two similar values into the database, e.g the user id which should be unique. Here is some sample code, Please help me.
    String s10 = req.getParameter("T10");
    String s11 = req.getParameter("T11");
    rs = st.executeQuery("select * from Register where userid='"+s10+"' ");
    if(rs.next())
         sos.println("Sorry the user already exists");
    else
    int x = st.executeUpdate("insert into Register values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"',"+s6+","+s7+",'"+s8+"','"+s9+"','"+s10+"','"+s11+"')");
    Thaks in advance
    Uma               

    Hi reddy
    Your code works will be perfect with slight changes whucah are as below:
    String s10 = req.getParameter("T10");
    String s11 = req.getParameter("T11");
    rs = st.executeQuery("select * from Register where upper(userid)='"+s10.toUpperCase()+"' ");
    if(rs.next())
    sos.println("Sorry the user already exists");
    else
    int x = st.executeUpdate("insert into Register values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"',"+s6+","+s7+",'"+s8+"','"+s9+"','"+s10+"','"+s11+"')");
    In the above Query we will get a unique userids it may be smallcase or Uppercase
    This will help u
    Cheers
    Rambee

  • Row values into column....

    Hi Experts,
    Can i add column values into a single cell. Like my requirement is i want to add values of Name column in a single cell of some other table. For example if Table A contains A, B, C D names then in second table i want all these name in one cell as ABCD. I'm not able to find solution. please help me. i'm working on ODI. Any help or clue.
    Regards
    -Kirti

    Hi,
    2 suggestions:
    1) If you have a constant number of columns you could put, at an interface, so much "instances" of the datastore as the number of columns, create the join and put the necessary filter at each "instance". The mapping will be the concatenation of the column from each instance
    or
    2) Create a procedure where you have the select column_to_be_concatenated at Source TAB and an update of that at Target TAB (if necessary you can define a dynamic PL/SQL to deal with insert update!)
    Does it help you?

  • When executing query...in the result i want to display each row values

    Hi All,
    When executing query...in the result area i want to display  each row values.
    Example:  query result is like this
    Business Area   Sales   Material 
    kh02                 1000      2000
                            2000       300
                            5000        400
                            6990       1000
    Kh03                1400        700
                             200        500
                              50          60
    but i need like this
    kh02               1000         2000
    kh02                500           600
    kh02                400           300
    kh03                1400         700
    kh03               200            500
    Why i need like this because am exporting to Excel spread sheet and i have to send as i show above ....i am doing manual but the file is very big like 95, 969 records i have to change manual...like this i have to change 8 files.
    please advice me easy way
    i willl be very gr8ful
    Thanks
    sidhartha

    Hi,
    that'S exactly what hide repeated key values does. If this option is on your result is:
    Kh02 1000 1500
    blank 500 456
    blank 600 700
    kh03 400 500
    balnk 500 600
    If you turn it off, the result will be:
    Kh02 1000 1500
    Kh02 500 456
    kh02 600 700
    kh03 400 500
    kh03 500 600
    Exaclty what you want. Try it, it should work
    Regards,
    Juergen

  • How to merge two A5 pages into a single  A4 page.

    I have three PDF documents that I want to print duplexed onto a single A4 sheet. The first two pages (front and back) are A5 which is causing a problem when printing as it will not allow me to print in booklet format without cropping the back page.
    Is there any way to combine the two A5 pages into a single A4 page within Acrobat??
    I am currently running Acrobat 6.0 Standard on Windows XP SP2

    When you have been around since AA5 and earlier, the printer used to be the trick to doing things. Since AA5 a lot of the features have been built into Acrobat and it might be possible to create the page in another way. However, the print approach should still work.

  • Update two different tables by a single sql query:

    Hi All,
    i need to update two different talbes in a single sql query..
    i m using the following query
    UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12
    AND
    UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    i m getting the following error:
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43093] An error occurred while processing the EXECUTE PHYSICAL statement. [nQSError: 17001] Oracle Error code: 936, message: ORA-00936: missing expression at OCI call OCIStmtExecute: UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12 . [nQSError: 17011] SQL statement execution failed. (HY000)
    SQL Issued: EXECUTE PHYSICAL CONNECTION POOL writeback UPDATE FT_User_Alert SET Subscription = 'W' where product_key=1 and measure_key = 12 AND UPDATE LU_Monthly_Alert_Budget_Sheet SET Min_Red_Range ='16.0' AND Max_Green_Range ='24.0'AND Max_Red_Range ='27.0'AND Min_Green_Range ='16.0' where product_key='1' and measure_key = 12
    but when i m ushin the same query in Microsoft SQL Server it executes properly:
    please help me out...

    Duplicate thread. I've already answered on your other thread...
    update two different tables by a single sql query:

  • I am wanting to exactly match two ID numbers from two differing worksheets within one work book. Once matched I am wanting to retrieve a row value from the second worksheet into the first. Any help much appreciated.

    I am wanting to exactly match two ID numbers from two worksheets within the one work book. ID numbers are non linear. Once exactly matched I wish to retrieve a corresponding row value from worksheet two and have it appear in worksheet one against the correct ID number. I have been looking at IF, VLOOKUP, and MATCH functions and suspect that what I want to do requires a combination of two or more. Any help will be greatly appreciated.
    regards Vaughanh

    Vaughan,
    Data A:D is all cells start at column A thru column D.
    There is built-in help using the menu item "View > Show Function Browser"  in the search field (top right) you can enter vlookup and you will see the detailed description.
    From this we see:
    VLOOKUP
    (search-for, columns-range, return-column, close-match)
    search-for:  The value to find. search-value can contain any value type.
    columns-range:  A range of cells. range is a reference to a single range of cells, which may contain values of any type.
    return-column:  A number that specifies the relative column number of the cell from which to return the value. return-column is a number value. The leftmost column in the range is column 1.
    close-match:  An optional value that determines whether an exact match is required.
    close match (TRUE, 1, or omitted):  If there’s no exact match, select the column with the largest top-row value that is less than the search value. Wildcards can’t be used in search-for.
    exact match (FALSE or 0):  If there’s no exact match, return an error. Wildcards can be used in search-for.
    So... the 2,0 means return the value form the same row as the lookup value but from the 2nd column of the range.  3, 0 means from the 3rd column.  the ", 0" means exact match

  • Concat rows values into single column

    Hi All,
    How can I concat values of a multiple rows into a single column by separating them by comma.
    Eg:
    SELECT empno FROM emp;
    empno
    1
    2
    3
    4
    I want output should be:
    Empnos
    1,2,3,4
    Thanks & Regards,
    Danish

    MichaelS wrote:
    Or
    SQL>  select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()').extract('//text()') ,',') empnos from emp
    EMPNOS                                                                         
    7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934 
    Hi Michael,
    is it an error or is it correct to put extract 2 times? This is giving to me the same result:
    select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()'),',') empnos from emp;
    EMPNOS                                                                         
    7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934           Regards.
    Al

  • Copy data of two rows together into a new row

    Hello everyone.
    I have a question about copying data of two existing rows together into a new third row.
    See this short example:
    This is the current situation. The rows STATE_1 and STATE_2 contain different separated information.
    In the past data were saved randomly in one of those rows.
    This is the table State:
    ID
    Cust_ID
    STATE_1
    STATE_2
    STATE_3
    1
    88
    Customer is waiting.
    Call from yesterday.
    2
    11
    Mr. Smith, no answer.
    Waiting until December
    3
    11
    Pls create PO.
    Old PO was cancelled
    4
    5
    No access to system.
    From now on everything has to be saved to the empty STATE_3 but I also need the old entries from the past which also have to be copied together into STATE_3
    like this:
    ID
    Cust_ID
    STATE_1
    STATE_2
    STATE_3
    1
    88
    Customer is waiting.
    Call from yesterday.
    Customer is waiting. Call from yesterday
    2
    11
    Mr. Smith, no answer.
    Waiting until December.
    Mr. Smith, no answer. Waiting until December.
    3
    11
    Pls create PO.
    Old PO was cancelled.
    Pls create PO. Old PO was cancelled.
    4
    5
    No access to system.
    No access to system.
    Is there an easy SQL-command?
    Thanks for any help.

    Hi,
    DB2000 wrote:
    Hello everyone.
    I have a question about copying data of two existing rows together into a new third row.
    See this short example:
    This is the current situation. The rows STATE_1 and STATE_2 contain different separated information.
    In the past data were saved randomly in one of those rows.
    This is the table State:
    ID
    Cust_ID
    STATE_1
    STATE_2
    STATE_3
    1
    88
    Customer is waiting.
    Call from yesterday.
    2
    11
    Mr. Smith, no answer.
    Waiting until December
    3
    11
    Pls create PO.
    Old PO was cancelled
    4
    5
    No access to system.
    When you say "row", do you mean "column"?
    DB2000 wrote:
    Because in this case STATE_1 and STATE_2 are only text of a log file/history.
    So I think 1NF isn't really violated and because of performance of the database in this case it's better to put obsolete rows together.
    Why do you think that?
    The definition of First Normal Form is that every column of every row contains 1 piece of information, not a variable number of pieces.  Whether or not that data is only text of a log file/history has nothing to do with it.
    You might claim you have good reasons (such as performance) for violating First Normal form, but you can't say that you're not violating it.

  • How to combine  two user prompts into 1 single prompt from two Webi Queries

    Hi All,
    I developed a single webi report from two different queries on top of 2 BW OLAP universe .
    Here I have one user input prompt for each query so I want to combine them into one single user input promt which  should pass the user input value to both the Webi queries feeding data to the  single webi report.
    I found that the webi doc has auto checked merge dimensions enabled but it is not providing combined resluts from both the queries .
    Any inputs are greatlt appreciated.
    Thanks

    Stratos
    Firstly ,I appreciate your responses for my two questions.
    Both the prompts I am using are from the masterdata and they are similar.data types.I think the transactional data is not available in BW for one of the prompt ,hence I am not getting consistent data.
    Anyway will do further investigation in finding similarities and let you know.
    Thanks a lot

  • How to store all the columns values into one single column

    Hi All,
    this is my file layout,i am receiving the data in below format only
    emp_no,c1,c2,c3,c4,c5
    100 ,1 ,0 ,1 ,0,1
    200 ,1 ,0 ,1 ,0,1
    300 ,1 ,0 ,1 ,0,1
    but i want to store that above data into my table like(from c1 to c5 columns values i want to store in period column)
    emp_no,period
    100 ,1
    100 ,0
    100 ,1
    100 ,0
    100 ,1
    200 ,1
    200 ,0
    200 ,1
    200 ,0
    200 ,1
    300 ,1
    300 ,0
    300 ,1
    300 ,0
    300 ,1
    please help me

    Strange but this is it
    Processing ...
    with original as (
         select 100 as id ,1 as v1,0 as v2,1 as v3,0 as v4,1 as v5
         from dual
         union all
         select 200 ,1 ,0 ,1 ,0,1
         from dual
         union all
         select 300 ,1 ,0 ,1 ,0,1
         from dual
    select id,v1 as res_row
    from original
    union all
    select id,v2
    from original
    union all
         select id,v3
         from original
    union all
         select id,v4
         from original
    union all
         select id,v5
         from original
                      ID                                   RES_ROW
                                       100                                      1
                                       200                                      1
                                       300                                      1
                                       100                                      0
                                       200                                      0
                                       300                                      0
                                       100                                      1
                                       200                                      1
                                       300                                      1
                                       100                                      0
                                       200                                      0
                                       300                                      0
                                       100                                      1
                                       200                                      1
                                       300                                      1
    15 row(s) retrievedBye Alessandro

Maybe you are looking for

  • Credit memo request

    Dear Gurus , I hv created Four sales document types  ,I maintained four different pricing procedures for each sales doc type . Assigned different doc procedure indicator as follows . Sales doc type   doc pricing proc indicator  Billing type ZS1      

  • Hyperlinks to external word files convert to pdf

    Hello! I have many Word documents (version 2007), which are linked among themselves through hyperlinks. Now, I want to convert these documents in pdf files (Adobe Acrobat Prof. 7.0). The problem of the pdf files are the hyperlinks: They still link to

  • Mac book admin password

    I have forgotten my admin password for my mac book pro...how to reset? Regards Chris

  • Download Tomcat 5

    I'm new to JSP/Servlet. I would like to know which Tomcat 5 with the extension "exe" and "zip". Which one i should download and what is the different?

  • EAP-TLS or PEAP authentication failed during SSL handshake error

    I have 2 Windows 2003 ACS 3.2 servers. I am in the process of upgrading them to ACS 4.0. I am using them for WPA2/PEAP wireless authentication in a WDS environment. I recently upgraded one to ACS 4.0 and ever since that time some (not all) of my Wind