calculation of the average using sql

Hi all

My table structure is

--------------------------------------
ID name notes starting_date end_date
--------------------------------------


workingdays = end_date-starting_date


I had a query


Select name, max (case when remarks = remarks then end notes).
Max (case when id = id then end_date-starting_date end),
AVG(end_date-starting_date) average t_action_items
Rollup (name, end_date-starting_date) group;


who's out like that

Name of the average Workingdays remarks
--------------------------------

x 20 20 aaa
BBB 10 20 x
AAA 10 15
y ccc 19
DDD y 8
CCC 8 13.5
CCC 8 14.2

But I need output like this, how can I do that someone please guide me

Name of the remarks Workingdays
------------------------

aaa 20 x
BBB 10 x
15 > x average
y ccc 19
DDD y 8
13.5-> average for y


Forgive me, I can't able to align to the right format, I think that with data you can seggregate

Thanks in advance...

Published by: Paappu on March 20, 2009 09:50

Hello

I have used WITH clause to show the result. You use just SELECT it with your table it will work.

SQL> SELECT * FROM T;

NAME   REMARK        START_DT  END_DT
------ ------------- --------- ---------
Mark   Design        15-FEB-09 15-FEB-09
Hendry Coding        08-JUN-08 15-JUN-08
steve  Testing       29-OCT-08 04-NOV-08
JAMES  POC           01-MAR-09 01-MAR-09
JAMES  DOCUMENTATION 01-MAR-09 09-MAR-09

SQL>     SELECT Name,Remark, SUM(work_hrs), AVG(work_hrs) FROM (
  2      SELECT name,remark ,start_dt,end_dt,SUM(end_dt-start_dt) OVER (PARTITI
N BY name,remark ORDER by Name) work_hrs
  3      FROM T)
  4    GROUP BY ROLLUP(name,remark);

NAME   REMARK        SUM(WORK_HRS) AVG(WORK_HRS)
------ ------------- ------------- -------------
Hendry Coding                    7             7
Hendry                           7             7
JAMES  DOCUMENTATION             8             8
JAMES  POC                       0             0
JAMES                            8             4
Mark   Design                    0             0
Mark                             0             0
steve  Testing                   6             6
steve                            6             6
                                21           4.2

10 rows selected.

SQL>

Kind regards

Tags: Database

Similar Questions

  • calculation of the average value of the sorted data and polar route drawing

    Hello

    I did a VI that calculates the average value of the wind rotor/speed-ratio in the sections of 30 degrees (wind direction). He also called the polar plot of calculated data. Everything works, but I would like to make more detailed calculations and drawings, by increasing the resolution to 1 degree, or...

    Problem is VI, I did, is not easy on a large scale. At the moment, I have 12 parallel structures of switch-box to calculate the average value and build the array function to collect data calculated for Polar plot to draw the image in real time. I know it's probably the worst way to do it, but since I have done a few things with LV, it was the only way I managed to do what I wanted.

    Now, if I continue in same way to reach my goal, I have to create 360 Parallels switch-case structures... that are crazy.

    Something like the calculation of the average of the table or matrix (zero/empty values should not be calculated on average) inside the loop or similar way would probably be the best solution.

    So, polar plot drawing is not a problem, but creating a reasonalbe average metering system is. Any ideas?

    I would also like to rotare northward to the top (0 deg), and degrees of increase in a clockwise direction on polar ground dial plate (as on the compass).

    VI on the attachment. (simplified version of the complete system)

    I have signals:

    -Wind speed

    -wind direction

    -Rotor speed

    I want to:

    -calculate the average value of the speed of the wind / rotor - ratio in sections (5 degrees, 1 degree)

    -Draw a polar path of the wind rotor/speed-ratio of averages in propotion of wind direction

    I'm using LabView 2009

    Thank you very much.

    It is closer to what you're looking for?

  • exclusion of a calculation of the average value

    Hello people from Adobe,.

    I am trying to exclude the "NC" 10 value are used to fill an average value (average rating of text box) on a form, I created.  I used the script from another topic on the exact topic thread, but I modified to fit my needs.  I think that it is a quick fix very.  For some reason, I don't get the average of all 10 drop boxes in my text box.  Can someone check this script and see what I might be missing.  The text box displays '0' because of this line event.value = 0;

    What Miss me?

    Here is the code:

    Average values of non - NA;

    var aFieldNames = new Array ("ListeDéroulante1", "Dropdown2", "Dropdown3", "Dropdown4", "Dropdown5", "Dropdown6", "Drop-down list 7", "Dropdown8", "Dropdown9", "Dropdown10");

    counter to the values non - NA;

    var nCount = 0;

    variable for values of sum of non - NA;

    nSum var = 0;

    default value of result if no average not calculated;

    Event.Value = 0;

    Table of process of domain names;

    for (i = 0; i < aFieldNames.length; i ++) {}

    If (this.getField(aFieldNames[i]).valueAsString! = "NA") {}

    field doesn't have a value of "NA";

    nCount ++; incrementing counter

    nSum += Number (this.getField(aFieldNames[i]).value). Add the value of the sum

    } / / end of value not of NA;

    } / / end of treatment a loop field;

    calculate the average;

    If (nCount! = 0) {}

    divisor of zero, so we can calculate the average;

    Event.Value = nSum / nCount;

    }

    I noticed that there 'Dropdown 7' as opposed to 'Dropdown7', which is what the field other names are similar. Could this be it?

  • XML data in the table using sql/plsql

    Hi experts,

    Could you please help with the following requirement. I have the tags xml (.xml on a server file) below. I need to access this file and read the XML and insert into the db table using sql and plsql. Is it possible with the cdata below? And there is a nested this table.

    Could someone please guide me if you have a sample code file and xml.

    <? XML version = "1.0" encoding = "UTF-8"? >

    < generation_date > <! [CDATA [17/11/2015]] > < / generation_date >

    < generated_by > <! [CDATA [Admin Admin]] > < / generated_by >

    < year > <! [CDATA [2015]] > < / year >

    < month > <! [CDATA [01]] > < / month >

    < author >

    < author > <! [CDATA [user author]] > < / author > < author_initial > <! [CDATA [user]] > < / author_firstname > < author_country > <! [CDATA [author]] > < / author_lastname >

    < author_email > <! [CDATA [[email protected]]] > < / author_email >

    < author_data_01 > <! [CDATA []] > < / author_data_01 >

    < author_data_02 > <! [CDATA []] > < / author_data_02 >

    < items >

    < article_item >

    < article_id > <! [CDATA [123456]] > < / article_id >

    < publication > <! [CDATA [Al Bayan]] > < / publication >

    < section > <! [CDATA [Local]] > < / section >

    < issue_date > <! [CDATA [11/11/2015]] > < / issue_date >

    < page > <! [CDATA [2]] > < / print this page >

    < article_title > <! [CDATA [title.]] > < / article_title > < number_of_words > <! [CDATA [165]] > < / number_of_words >

    < original_price > <! [CDATA [200]] > < / original_price >

    < original_price_currency > <! [CDATA [DEA]] > < / original_price_currency >

    < price > <! [CDATA [250]] > < / price >

    < price_currency > <! [CDATA [DEA]] > < / price_currency >

    < / article_item >

    < / articles >

    < total_amount > <! [CDATA [250]] > < / total_amount >

    < total_amount_currency > <! [CDATA [DEA]] > < / total_amount_currency >

    < / author >

    < / xml >

    Thanks in advance,

    Suman

    XMLTABLE using...

    SQL > ed
    A written file afiedt.buf

    1 with t (xml) as (select xmltype ('))
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [[12 [email protected]]] >
    13
    14
    15
    16
    17
    18
    19


    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33 ") of the double)"
    34-

    35 end of sample data
    36-
    37 - assumptions:
    (38 - a) XML may have several tags
    (39 - b) each may contain more
    40-
    41 select x.gen_by, x.gen_date, x.mn, x.yr
    42, y.author, y.auth_fn, y.auth_ln, y.auth_cnt, y.auth_em, y.auth_d1, y.auth_d2

    43, z.id, z.pub, z.sec, z.iss_dt, z.pg, z.art_ttl, z.num_wrds, z.oprice, z.ocurr, z.price, z.curr
    44 t
    45, xmltable ('/ authxml')
    from $ 46 t.xml
    path of 47 columns gen_date varchar2 (10) '. / generation_date'
    48, path of varchar2 (15) of gen_by '. / generated_by'
    49, path of varchar2 (4) year '. "/ year"
    50 varchar2 (2) mn road '. "/ month"
    51, path of xmltype authors '.'
    52                 ) x
    53, xmltable ('/ authxml/authors ')
    from $ 54 x.authors
    author of 55 path of varchar2 columns (15) '. / author'
    56, path of varchar2 (10) of auth_fn '. / author_firstname'
    57, path of varchar2 (10) of auth_ln '. / author_lastname'
    58 road of VARCHAR2 (3) auth_cnt '. / author_country'
    59 road of varchar2 (20) of auth_em '. / author_email'
    60 road of varchar2 (5) of auth_d1 '. / author_data_01'
    61, path of varchar2 (5) of auth_d2 '. / author_data_02'
    62, path of xmltype articles '. / Articles'
    63                 ) y
    64, xmltable ('/ Articles/article_item ')
    from $ 65 y.articles
    path id 66 number columns '. / article_id'
    67, path of varchar2 (10) pub '. ' / publication.
    68 road of varchar2 (10) dry '. / section'
    69, path of varchar2 (10) of iss_dt '. / issue_date'
    70 road of VARCHAR2 (3) pg '. "/ print this page"
    71, path of varchar2 (20) of art_ttl '. / article_title'
    72, path of varchar2 (5) of num_wrds '. / number_of_words'
    73, path of varchar2 (5) of oprice '. / original_price'
    74 road to VARCHAR2 (3) ocurr '. / original_price_currency'
    75, path of varchar2 (5) price '. "/ price"
    76, path of VARCHAR2 (3) curr '. / price_currency'
    77*                ) z
    SQL > /.

    GEN_DATE GEN_BY YEAR MN AUTHOR AUTH_FN AUTH_LN AUT AUTH_EM AUTH_ AUTH_ ID PUB DRY ISS_DT PG ART_TTL NUM_W OPRIC HEARTS PRICE OCU
    ---------- --------------- ---- -- --------------- ---------- ---------- --- -------------------- ----- ----- ---------- ---------- ---------- ---------- --- -------------------- ----- ----- --- ----- ---
    17/11/2015 Admin Admin 2015 01 user author user author [email protected] 123456 UAE Al Bayan Local 11/11/2015 2 is the title.   165 200 AED AED 250

    Of course, you'll want to change the types of data, etc. as needed.

    I assumed that the XML can contain several "" sections and that each section can contain several entries.

    Thus the XMLTABLE aliasing as 'x' gives information of XML, and supplies the data associated with the XMLTABLE with alias 'y' which gets the multiple authors, which itself section of the XMLTABLE with alias 'z' for each of the article_item.

    CDATA stuff are handled automatically by SQLX (XML functionality integrated into Oracle's SQL)

  • Calculation of the average

    Hello

    I'm figuring the average of some values divided by ID & month.

    Please see test the scripts below, I use Oracle D/B v 11.2.0.4:

    CREATE TABLE TEST)
    IDENTIFICATION NUMBER,
    MONTH, DATE, TIME,
    CUST_NUM VARCHAR2 (4).
    RATE 1 NUMBER,
    NATUREL2 NUMBER);


    INSERT TEST VALUES (4586, 1ST JANUARY 13 "," 0001", 26.35, 78.45);
    INSERT TEST VALUES (4586, 1 JANUARY 13 ', ' 0002', 13.21, 33.33);
    INSERT TEST VALUES (4586, 1 JANUARY 13 ', ' 0003', 54.69, 79.34);
    INSERT TEST VALUES (4586, 1ST JANUARY 13 "," 0004", 99.36, 100);
    INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0005', 89,63, 78.25);
    INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0006', 13.11, 49.36).
    INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0007', 78.63, 85.21);
    INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0009' 63,22, 100);
    INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0010' 22.35, 100);
    INSERT TEST VALUES (4586, 1 FEBRUARY 13 ', ' 0011', 41.11, 99,63);
    INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0012', 25.23, 45.25);
    INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0013', 13.11, 56.54);
    INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0014', 56.24, 50.00);
    INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0015', 11.23, 100);
    INSERT TEST VALUES (4586, 1 MARCH 13 ', ' 0016', 100, 100);
    Insert test values (4586, 1 March 13 ', ' 0017', 99.99, 99,63);

    I want to calculate the average of the rates of column 1 by id & months but the request is also a grouping of the cust_num:

    SELECT ID, MONTH, CUST_NUM, AVG (CASE WHERE rate1 <>0 then end rate1) avg
    OF THE TEST
    Group by id, month, cust_num
    order by 2, 3

    Expected results:

    4586, 13, JANUARY 1, 0001 48.40
    4586, 1 JANUARY 13, 0002, 48.40
    4586, 1 JANUARY 13, 0003, 48.40
    4586, 1 JANUARY 13, 0004 48.40
    4586, 1ST FEBRUARY 13, 0005 51,34
    4586, 1ST FEBRUARY 13, 0006 51,34
    4586, 1ST FEBRUARY 13, 0007 51,34
    4586, 1ST FEBRUARY 13, 0009, 51,34
    4586, 1ST FEBRUARY 13, 0010 51,34
    4586, 1ST FEBRUARY 13, 0011 51,34
    4586, 1 MARCH 13, 0012 41.16
    4586, 1 MARCH 13, 0013 41.16
    4586, 1 MARCH 13, 0014 41.16
    4586, 1 MARCH 13, 0015 41.16
    4586, 1 MARCH 13, 0017 41.16


    The average should be the same for each id and the month, can anyone help?

    Thank you

    Hello

    sliderrules wrote:
    Hello

    I'm figuring the average of some values divided by ID & month.

    Please see test the scripts below, I use Oracle D/B v 11.2.0.4:

    CREATE TABLE TEST)
    IDENTIFICATION NUMBER,
    MONTH, DATE, TIME,
    CUST_NUM VARCHAR2 (4).
    RATE 1 NUMBER,
    NATUREL2 NUMBER);

    Thanks for posting the CREATE TABLE and INSERT the statementsl which is very useful.

    INSERT TEST VALUES (4586, 1ST JANUARY 13 "," 0001", 26.35, 78.45); ...

    The month of the column is a DATE; do not try to insert values such as 1 January 13 VARCHAR2' in a DATE column.

    I want to calculate the average of the rates of column 1 by id & months but the request is also a grouping of the cust_num:

    GROUP BY means that, regardless of the number of rows in each group in the table, you want to only 1 row of output for the whole of the group. In this case, you won't have the output to have exactly the same number of rows as the table? If so, then do not use GROUP BY.

    SELECT ID, MONTH, CUST_NUM, AVG (BOX WHEN rate1 <> 0 then end rate1) avg
    OF THE TEST
    Group by id, month, cust_num
    order by 2, 3

    Expected results:

    4586, 13, JANUARY 1, 0001 48.40
    4586, 1 JANUARY 13, 0002, 48.40
    4586, 1 JANUARY 13, 0003, 48.40
    4586, 1 JANUARY 13, 0004 48.40
    4586, 1ST FEBRUARY 13, 0005 51,34
    4586, 1ST FEBRUARY 13, 0006 51,34
    4586, 1ST FEBRUARY 13, 0007 51,34
    4586, 1ST FEBRUARY 13, 0009, 51,34
    4586, 1ST FEBRUARY 13, 0010 51,34
    4586, 1ST FEBRUARY 13, 0011 51,34
    4586, 1 MARCH 13, 0012 41.16
    4586, 1 MARCH 13, 0013 41.16
    4586, 1 MARCH 13, 0014 41.16
    4586, 1 MARCH 13, 0015 41.16
    4586, 1 MARCH 13, 0017 41.16

    The average should be the same for each id and the month, can anyone help?

    Use the analytical AVG, not the aggregate function.

    SELECT    id
    ,        month
    ,        cust_num
    ,        AVG (NULLIF (rate1, 0)) OVER ( PARTITION BY  id
                                                   ,            month
                               )     AS avg_rate1
    FROM      test
    ORDER BY  month
    ,            cust_num
    ;
    
  • If / then the Concepts using SQL not PL/SQL - avoid ORA-00942

    Hello

    Im trying to write a monitor which works in all of 80 db (where there is only applicable 7 db)-I want it simply returns the null value or no line on the DB is not required on as it is integrated into a model

    A simplified version of the query "select col1, col2 from cat1.helptab.

    It's very good for all the DB who actually have cat1.helpteb in their breast, but for those who are not obviously ORA-00942: table or view does not exist is returned.

    I need to write a SQL statement that can move, * due to specific requirements, I can't use the PL/SQL for this *.

    Any ideas how I can construct the statement above return null or 'no reurned lines' if cat1.helptab does not exist in the comic book?... instead of return ORA-00942

    Any help would be appreciated

    What is the interms impact of objects are created in the DB? nothing?

    All operators/functions are generally available out of the box in a standard enterprise db installation.
    Your admin could gave a restricted access to (or uninstalled) dbms_xmlgen well - one thing I would check beforehand.

    How this same method would work for the selection of a column that does not exist?

    Almost the same:

    SQL> select extract (x.column_value, 'ROW/DEPTNO/text()').getnumberval () deptno,
           extract (x.column_value, 'ROW/DNAME/text()').getstringval () dname,
           extract (x.column_value, 'ROW/ALERT/text()').getstringval () alert
      from all_tables,
           table (
             xmlsequence (
               dbms_xmlgen.getxmltype ('select deptno, dname, ''WARNING'' alert from ' || owner || '.' || table_name || ' where deptno > 30').extract (
                 'ROWSET/ROW'))) x
     where owner = 'MICHAEL'
       and table_name = 'DEPT'
    /
        DEPTNO DNAME                          ALERT
    ---------- ------------------------------ ------------------------------
            40 OPERATIONS                     WARNING
            50 SALES                          WARNING                       
    
    2 rows selected.
    
  • Unable to connect to the database using SQL * more

    Hi, I have Oracle 10 g XE installed in my labtop, and I can't connect using SQL * more.
    I can connect using the User Interface of navig however, I could do after the following procedure to change the password for the sys account:
    -Open a command prompt
    -type sqlplus
    -On the line "Enter user name", enter the sysdba virtue
    -On the SQL > prompt, type alter user sys identified by NewPassword;

    But the thing is that even if I am able to connect using sys/NewPassword from my browser UI, I don't get the same result when do this using the SQL prompt.

    What I try to do is the following:
    SQL > connect sys/NewPassword
    Can I get first a warming of the planet by saying I should use sysdba or sysoper to connect to the system account, but none of those who work.

    Can anyone advice me on this subject?

    Thanks in advance

    Does make sense at all?

    You really need to Read The Fine Manual
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e16508/TOC.htm

    When you log in as USER "SYS" DB must be described as 'AS SYSDBA'

    sqlplus
    / as sysdba
    SHOW USER;
    -line above indicates that you are now connected to the DB as "SYS"!

    SQL > CONNECT SYS / AS SYSDBA

  • To change the way of afficherdans the data using SQL

    I have data as follows:

    Name age
    Tom 24
    Harry 45
    Mona 30


    I want to convert these data in the way below

    Name1, name2 Age1 Age2 Name3 3
    24 45 30 Mona Harry Tom



    How can I do the same thing using SQL?

    Why not try to search this forum of 'PIVOT' to make this small change yourself?

    SQL> set line 1000
    SQL> WITH t AS (SELECT 101 empid,45 marks,8 rank FROM dual UNION ALL
      2             SELECT 101 empid,62 marks,7 FROM dual UNION ALL
      3             SELECT 101 empid,80 marks,2 FROM dual UNION ALL
      4             SELECT 102 empid,67 marks,5 FROM dual UNION ALL
      5             SELECT 102 empid,56 marks,6 FROM dual UNION ALL
      6             SELECT 103 empid,87 marks,7 FROM dual UNION ALL
      7             SELECT 103 empid,55 marks,9 FROM dual UNION ALL
      8             SELECT 103 empid,60 marks,6 FROM dual UNION ALL
      9             SELECT 103 empid,70 marks,3 FROM dual
     10             )
     11  ---End of Sample Data
     12  ---Now the original query.
     13  SELECT empid, MAX(DECODE(rn1,1,marks)) Marks1,MAX(DECODE(rn1,1,rank)) Rank1
     14              , MAX(DECODE(rn1,2,marks)) Marks2,MAX(DECODE(rn1,2,rank)) Rank2
     15              , MAX(DECODE(rn1,3,marks)) Marks3,MAX(DECODE(rn1,3,rank)) Rank3
     16              , MAX(DECODE(rn1,4,marks)) Marks4,MAX(DECODE(rn1,4,rank)) Rank4
     17  FROM
     18     (SELECT empid,marks,rank,
     19      ROW_NUMBER() OVER(PARTITION BY empid ORDER BY marks) rn1
     20      FROM t)
     21  GROUP BY empid;
    
         EMPID     MARKS1      RANK1     MARKS2      RANK2     MARKS3      RANK3     MARKS4      RANK4
    ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
           101         45          8         62          7         80          2
           102         56          6         67          5
           103         55          9         60          6         70          3         87          7
    
    SQL> 
    
  • Extrapolation of the records using SQL

    Hello

    Need help with SQL:

    I have to blow up the arrival of a stream to produce records for every day.
    Let me explain-

    Inflow is an incremental flow - there is a record only if balance_usd is
    updated.
    Act date_key balance_usd
    101 20090201 230
    101 20090210 3400
    101 20090221 2000

    Desired fact - a line for each day, previous balance repeated for table
    the day forevery account unless there is a new record in the incoming stream
    (marked with * below)

    Act date_key balance_usd
    101 20090201 230 *.
    101 20090202 230
    101 20090203 230
    101 20090204 230
    101 20090205 230
    101 20090206 230
    101 20090207 230
    101 20090208 230
    101 20090209 230
    101 20090210 3400 *.
    101 20090211 3400
    101 20090212 3400
    101 20090213 3400
    101 20090214 3400
    101 20090215 3400
    101 20090216 3400
    101 20090217 3400
    101 20090218 3400
    101 20090219 3400
    101 20090220 3400
    101 20090221 2000 *.
    101 20090222 2000
    101 20090223 2000
    101 20090224 2000
    101 20090225 2000
    101 20090226 2000
    101 20090227 2000
    101 20090228 2000

    Reason to put in as a form of "exploded" is to be able to
    to calculate the average balance for a given period (months).

    Is there a way to do this create a single sql statement or what I write
    a procedure?

    Thank you!

    Hello

    My solution is correct or not?

    You can explain further.

    Salim cordially.

  • The problem with the calculation of the average for the recurring value

    My task is to perform analysis, where in the table have ID to which she is assigned 10 measures (1-10) and each has its own value. I have to average of this what I take AVG (as) and I want to say. However, as prompcie Will I choose the second ID and I have two measures 1-10 time what I means account for 20 photos and I want to separate Average (two - each for 10 measures). Is there any possibility of Smash it? The use of a function or collection of rehearsals ?


    It looks like this:


    column 1 | column 2 | column 3 | AVG |


    ID |  Nr.  result | AVG?

    x | 1. 200 | AVG x?

    | 2. 210 |

    | 3. 210 |

    There | 1. 210 | is AVG?

    | 2. 208

    | 3. 200


    In column 4, I want to be avarage but another for id x and another for id y?

    is the result you are looking for:

    If Yes... then avg column formula is AVG (result BY id)

  • How to create a script for the calculation of the VO2max using text on a pdf form field values.

    I'm trying to create a script that calculates the VO2max based on user input in several text fields.

    My form is set up so that the user can enter values in the 4 fields of text:

    1 weight = weight in kilograms

    2. age = age in years

    3 time = time to walk 1 mile in decimal

    4. the heart rate (HR) = heart rate recovery immediately after you have finished walking 1 mile

    The VO2max equation that I use is:

    VO2max = 132.853 - (0.1692 * weight)-(0.3877 * Age) + (6,315) - (3.2649 * time)-(0.1565 * HR)

    After the user enters values in 4 text fields, I want the text of VO2max field automatically calculate the above equation and display the result to the user so that the user doesn't have to get all those numbers into a calculator.

    Any suggestions on how to write the script?

    Assuming that your domain names are what you entered in the formula, you can use the simplified field notation:

    132.853 - (0.1692 * weight)-(0.3877 * Age) + (6,315) - (3.2649 * time)-(0.1565 * HR)

    If you want the value to display only after al the data fields are complete you need to use a JavaScript calculation:

    function GetField (cName) {}
    oField var = this.getField (cName);
    if(oField == null) app.alert ("field of error for access to the" cName + "\nPlease verify the name of the field.", 1, 0 ");
    return oField;
    }

    var weight = GetField ("Weight");
    var Age is GetField ("Age");.
    var time = GetField ("Time");
    var h = GetField ("HR");

    Event.Value = "";
    If (Weight.value! = 0 & Age.value! = 0 & Time.value! = 0 & HR.value! = 0) {}
    Event.Value = 132.853 - (0.1692 * Weight.value)-(0.3877 * Age.value) + (6,315) - (3.2649 * Time.value)-(0.1565 * HR.value);
    }

  • How the group using SQL for the desired output.

    Hi all

    I am currently using oracle 10.2.0.4.0

    Create a table script:
    CREATE TABLE FORTEST
    ( gpno VARCHAR2(10 BYTE),
      classnumber  VARCHAR2(10 byte),
      age_min NUMBER,
      age_max NUMBER,
      amount NUMBER)
    INSERT statement:
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 01,0,29,1) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 01,30,35,2) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 01,36,40,3) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 02,0,29,1) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 02,30,35,2) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 02,36,40,5) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 03,0,29,1) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 03,30,35,2) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 03,36,40,3) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G124' , 01,0,29,1) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G124' , 01,30,35,2) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G124' , 01,36,40,3) 
    power required:
    gpno    classnumber    age_min    age_max    amount
    G123    1,3                0        29        1
    G123    1,3                30       35        2
    G123    1,3                36       40        3
    G123    2                  0        29        1
    G123    2                  30       35        2
    G123    2                  36       40        5
    G124    1                  0        29        1
    G124    1                  30       35        2
    G124    1                  36       40        3
    as for gpno g123, classnumber 1 and 3, the rates are the same in all the age_min and age_max they need to be grouped.
    even if gpno 123 classnumber 2 has the same rates as the classesnumber 1 and 3 for the age groups 0 to 29 and 30 to 35,
    rates are different for ages 36 to 40. so it should not be placed together. How can I do this in SQL

    any help is appreciated.

    Thanks in advance.

    Hello

    Thorny problem!

    Unfortunately, LISTAGG was created to the Oracle 11.2. About half of the complexity here is the aggregation of chain, i.e. forming the list of the classnumbers, as '1.3', using only functions available in Oracle 10.2.

    Here's a solution:

    WITH     got_gpno_classnumber_cnt   AS
    (
         SELECT     gpno, classnumber, age_min, age_max, amount
         ,     COUNT (*) OVER ( PARTITION BY  gpno
                                      ,            classnumber
                          )   AS gpno_classnumber_cnt
         FROM    fortest
    --     WHERE     ...     -- If you need any filtering, this is where it goes
    )
    ,     pairs          AS
    (
         SELECT    a.gpno
         ,       a.classnumber
         ,       MIN (b.classnumber)
                    OVER ( PARTITION BY  a.gpno
                              ,                    a.classnumber
                      )     AS super_classnumber
         FROM       got_gpno_classnumber_cnt  a
         JOIN       got_gpno_classnumber_cnt  b  ON   a.gpno     = b.gpno
                                      AND  a.age_min     = b.age_min
                                    AND  a.age_max     = b.age_max
                                    AND  a.amount     = b.amount
                                    AND  a.gpno_classnumber_cnt
                                            = b.gpno_classnumber_cnt
         GROUP BY  a.gpno
         ,            a.classnumber
         ,       b.classnumber
         HAVING       COUNT (*)     = MIN (a.gpno_classnumber_cnt)
    )
    ,     got_rnk          AS
    (
         SELECT DISTINCT
                 gpno, classnumber, super_classnumber
         ,     DENSE_RANK () OVER ( PARTITION BY  gpno
                                   ,                    super_classnumber
                                   ORDER BY          classnumber
                           )         AS rnk
         FROM    pairs
    )
    ,     got_classnumbers     AS
    (
         SELECT     gpno, classnumber, super_classnumber
         ,      SUBSTR ( SYS_CONNECT_BY_PATH (classnumber, ',')
                       , 2
                     )     AS classnumbers
         FROM     got_rnk
         WHERE     CONNECT_BY_ISLEAF = 1
         START WITH     rnk             = 1
         CONNECT BY     rnk             = PRIOR rnk + 1
              AND     gpno             = PRIOR gpno
              AND     super_classnumber  = PRIOR super_classnumber
    )
    SELECT DISTINCT
           g.gpno
    ,       c.classnumbers
    ,       g.age_min
    ,       g.age_max
    ,       g.amount
    FROM       got_gpno_classnumber_cnt  g
    JOIN       got_classnumbers         c  ON   c.gpno        = g.gpno
                                 AND  c.classnumber  = g.classnumber
    ORDER BY  g.gpno
    ,            c.classnumbers
    ;
    

    Out (just as you requested):

    GPNO       CLASSNUMBERS       AGE_MIN    AGE_MAX     AMOUNT
    ---------- --------------- ---------- ---------- ----------
    G123       1,3                      0         29          1
    G123       1,3                     30         35          2
    G123       1,3                     36         40          3
    G123       2                        0         29          1
    G123       2                       30         35          2
    G123       2                       36         40          5
    G124       1                        0         29          1
    G124       1                       30         35          2
    G124       1                       36         40          3
    
  • Create the view using SQL DEVELOPER

    I'm new to this forum :)

    11 GR 2, WIN2008 R2

    SQL Developer Version 3.2.09

    I am creating the data below view (view existing)

    Table: Dovmarker
    MARKERBOREHOLE                             UWI             MARKERSURFACE              Z
    WELLXXX               65372643AAAA     Cw     -982,985619574516
    WELLXXX               65372643AAAA     Cn     -1891,47401803955
    WELLXXX               65372643AAAA     J     -674,989528816517
    WELLXXX               65372643AAAA     K3     20,00165000429
    WELLXXX               65372643AAAA     Tr     125,000317308153
    WELLXXX               65372643AAAA     K1     -658,989731894024
    WELLXXX               65372643AAAA     Q     149,999999999549
    
    WELLYYY                          56618334AAAA     Jkm     -715,071442105268
    WELLYYY                          56618334AAAA     K3     36,9013966413975
    WELLYYY                          56618334AAAA     J2     -976,056079257549
    WELLYYY                          56618334AAAA     Tr     106,900507694299
    I try to describe the table and my goal :),

    each line describes wells, uwi(uniqe identifier), z (deppth), high (surface marker)

    I try to merge all lines with the same MARKERBOREHOLE/UWI and MARKERSURFACE contact coresponding Z (ascending) as MARKERSURFACE = Z.
    If it is posibble to reduce the number of decimals to 2.

    My idea to solve the problem:
    example: ' | ' is the delimiter
    WELLXXX    Q=149,999999999549 | Tr=125,000317308153 | K3=20,00165000429 |  K1=-658,989731894024 | J =-674,989528816517 | Cw=-982,985619574516 | Cn=-1891,47401803955
    WELLYYY   Tr=106,900507694299 | K3=36,9013966413975 |  Jkm=-715,071442105268 | J2=-976,056079257549
    or better (not enough knowledge ;))
    WELLXXX    Q=149,999999999549 
                     Tr=125,000317308153
                     K3=20,00165000429 
                     K1=-658,989731894024 
                     J =-674,989528816517 
                     Cw=-982,985619574516 
                     Cn=-1891,47401803955
    
    WELLYYY   Tr=106,900507694299 
                     K3=36,9013966413975 
                     Jkm=-715,071442105268 
                     J2=-976,056079257549
    Number of markersurface is different for each well


    I try to do it by the listagg function, but I have failled
    select markerborehole, listagg(z, ' | ') within group (order by z) as new1 
      from dovmarker
      group by markerborehole;
     
    result:
    WELLZZZ  -2575,95869465411 | -1891,47401803955 | -982,985619574516 | -674,989528816517 | -658,989731894024 | 
    WELLRRR -2376,96975480605 | -2376,96975480605 | -2308,97180590009 | -2308,97180590009 | -2206,47428534641 | -2206,47428534641 | -2163,97522524171
    When I tried to create new view in sql developer I occurred error;
    Error(s) parsing SQL:
    unexpected token near *!* in the following:
    select markerborehole, listagg(z, ' | ') within *!*group (order by z) as new1
    unexpected token near *!* in the following:
    select markerborehole, listagg(z, ' | ') within group *!*(order by z) as new1
    missing expression near *!* in the following:
    select markerborehole, listagg(z, ' | ') within group (*!*order by z) as new1
    Can you help me with this?

    Concerning
    Jaroslaw

    961148 wrote:
    I missed x

    Well Yes, my apologies, I has not changed all that.

    It's a simple way to format the Z value to 2 decimal places?

    Yes. It depends on if you want to use rounded, floor, ceiling, truncate or if you like a string always have 2 decimal places etc.
    Make your choice and customize according to your needs...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'WELLXXX' as MARKERBOREHOLE, '65372643AAAA' as UWI, 'Cw' as MARKERSURFACE, -982.985619574516 as Z from dual union all
      2             select 'WELLXXX', '65372643AAAA', 'Cn', -1891.47401803955 from dual union all
      3             select 'WELLXXX', '65372643AAAA', 'J', -674.989528816517 from dual union all
      4             select 'WELLXXX', '65372643AAAA', 'K3', 20.00165000429 from dual union all
      5             select 'WELLXXX', '65372643AAAA', 'Tr', 125.000317308153 from dual union all
      6             select 'WELLXXX', '65372643AAAA', 'K1', -658.989731894024 from dual union all
      7             select 'WELLXXX', '65372643AAAA', 'Q', 149.999999999549 from dual union all
      8             select 'WELLYYY', '56618334AAAA', 'Jkm', -715.071442105268 from dual union all
      9             select 'WELLYYY', '56618334AAAA', 'K3', 36.9013966413975 from dual union all
     10             select 'WELLYYY', '56618334AAAA', 'J2', -976.056079257549 from dual union all
     11             select 'WELLYYY', '56618334AAAA', 'Tr', 106.900507694299 from dual)
     12  --
     13  -- END OF TEST DATA - IGNORE ABOVE WITH CLAUSE
     14  --
     15  select z
     16        ,round(z,2) as round_z_2
     17        ,floor(z*100)/100 as floor_z_2
     18        ,ceil(z*100)/100 as ceil_z_2
     19        ,trunc(z,2) as trunc_z_2
     20        ,to_char(round(z,2),'fm9990.00') as string_z_2
     21* from t
    SQL> /
    
                      Z  ROUND_Z_2  FLOOR_Z_2   CEIL_Z_2  TRUNC_Z_2 STRING_Z
    ------------------- ---------- ---------- ---------- ---------- --------
     -982.9856195745160    -982.99    -982.99    -982.98    -982.98 -982.99
    -1891.4740180395500   -1891.47   -1891.48   -1891.47   -1891.47 -1891.47
     -674.9895288165170    -674.99    -674.99    -674.98    -674.98 -674.99
       20.0016500042900         20         20      20.01         20 20.00
      125.0003173081530        125        125     125.01        125 125.00
     -658.9897318940240    -658.99    -658.99    -658.98    -658.98 -658.99
      149.9999999995490        150     149.99        150     149.99 150.00
     -715.0714421052680    -715.07    -715.08    -715.07    -715.07 -715.07
       36.9013966413975       36.9       36.9      36.91       36.9 36.90
     -976.0560792575490    -976.06    -976.06    -976.05    -976.05 -976.06
      106.9005076942990      106.9      106.9     106.91      106.9 106.90
    
    11 rows selected.
    

    with above code I try to create a new view in SQL Developer, but I have error:

    Error(s) parsing SQL:
    Unexpected token near *!* in the following:
    select markerborehole, listagg(z,chr(10)) within *!*group(order by rn) as z
    Unexpected token near *!* in the following:
    select markerborehole, listagg(z,chr(10)) within group*!*(order by rn) as z
    Missing expression near  *!* in the following:
    select markerborehole, listagg(z,chr(10)) within group(*!*order by rn) as z
    

    What are all the {noformat}! * * {noformat} in the code? Delete them.

    Edit: or maybe your version of SQL Developer is not up-to-date and does not know the new LISTAGG function in 11g?

    Published by: BluShadow on 26-Sep-2012 09:41

  • The Clause using SQL type

    Version
    SQL> select *
      2  from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE     10.2.0.4.0     Production
    
    TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio
    NLSRTL Version 10.2.0.4.0 - Production
    My query
    with tmp AS (
      select 1 as num, 'karthik' as txt from dual UNION select 2 as num, 'john' as txt from dual UNION select 3 as num, '' as txt  from dual UNION select 4 as num, '' as txt  from dual UNION
      select 14 as num, 'tom' as txt from dual UNION select 15 as num, '' as txt from dual UNION select 26 as num, 'sam' as txt from dual UNION
      select 27 as num, '' as txt from dual UNION select 28 as num, '' as txt from dual
    )
    select *
    from
    (
    select num,txt,rw,'G'||dense_rank() over(order by (num-rw)) grp_id
    from
    (
    select 
    num, txt,row_number() over(order by num) rw
    from tmp
    )
    )
    model partition by(grp_id)
          dimension by(num)
          measures(txt,cast(null as varchar2(4000)) as last_row_col)
          rules (last_row_col[(num)] = max(txt)[num < cv()])
    
    GRP_ID                                           NUM TXT     LAST_ROW_COL
    ----------------------------------------- ---------- ------- --------------------------------------------------------------------------------
    G1                                                 1 karthik 
    G1                                                 2 john    karthik
    G1                                                 3         karthik
    G1                                                 4         karthik
    G3                                                26 sam     
    G3                                                27         sam
    G3                                                28         sam
    G2                                                14 tom     
    G2                                                15         tom
    Desired output:
    GRP_ID     NUM     TXT     LAST_ROW_COL
    G1     1     karthik     karthik
    G1     2     john     
    G1     3          
    G1     4          john
    G3     26     sam     
    G3     27          
    G3     28          sam
    G2     14     tom     
    G2     15          tom
    i.e.within Group (GRP_ID) the LAST_ROW_COL column must have the most recent (order by num desc) not null not the value that is displayed in the last line of this group in particular.

    So, it should be 'john' for the rest of the null values in the group G1 (Kiss will remain as for num = 1) which should appear on the final line of this group in particular.

    Thanks in advance.

    Published by: RUSSO on January 2, 2012 04:18

    RUSSO says:

    I thought that this could be done easily using the power of the sql model clause

    with tmp AS (
                 select 1 as num, 'karthik' as txt from dual UNION ALL
                 select 2 as num, 'john' as txt from dual UNION ALL
                 select 3 as num, '' as txt  from dual UNION ALL
                 select 4 as num, '' as txt  from dual UNION ALL
                 select 14 as num, 'tom' as txt from dual UNION ALL
                 select 15 as num, '' as txt from dual UNION ALL
                 select 26 as num, 'sam' as txt from dual UNION ALL
                 select 27 as num, '' as txt from dual UNION ALL
                 select 28 as num, '' as txt from dual
                )
    select  grp_id,
            num,
            txt,
            last_row_col
      from  tmp
      model
        dimension by(row_number() over(order by num) rw)
        measures(num,txt,txt last_row_col,cast(null as varchar2(5)) grp_id)
        rules(
              grp_id[any]       = 'G' || dense_rank() over(order by num[cv()] - cv(rw)),
              last_row_col[rw > 1] order by rw = case
                                                   when last_row_col[cv()] is null then last_row_col[cv() - 1]
                                                   else last_row_col[cv()]
                                                 end,
              last_row_col[rw > 1] order by rw = case last_row_col[cv() + 1]
                                                   when last_row_col[cv()] then null
                                                   else last_row_col[cv()]
                                                 end
             )
    /
    
    GRP_I        NUM TXT     LAST_RO
    ----- ---------- ------- -------
    G1             1 karthik karthik
    G1             2 john
    G1             3
    G1             4         john
    G2            14 tom
    G2            15         tom
    G3            26 sam
    G3            27
    G3            28         sam
    
    9 rows selected.
    
    SQL> 
    

    SY.

    Published by: Solomon Yakobson January 2, 2012 09:35

  • PLACE of the draw using SQL

    How can I write an SQL to generate a square for a period of time? Using only the SQL (not PL SQL).

    Assumption - two characters in the horizontal line is equal to a character vertically.

    Example of

    Suppose that if the length of the square is 7, then there will be a character in horizontal line 14 and 7 in vertical line.
    **************
    *            *
    *            *
    *            *
    *            *
    *            *
    **************
    Help, please.

    Published by: user10681556 on 10 Sep, 2009 01:26

    Alex Nuijten wrote:
    ... but I don't know Rob could come up with a more elegant solution ;)

    Not really.

    Only one rule less:

    SQL> select s square
      2    from dual
      3   model
      4         dimension by (0 i)
      5         measures (cast(null as varchar2(100)) s)
      6         rules
      7         ( s[for i from 1 to :sz increment 1] = '*' || rpad (' ',2*:sz - 2) || '*'
      8         , s[i in (1,:sz)] = replace(s[cv()],' ','*')
      9         )
     10  /
    
    SQUARE
    -------------------------------------------------------------------------------------
    
    ********************
    *                  *
    *                  *
    *                  *
    *                  *
    *                  *
    *                  *
    *                  *
    *                  *
    ********************
    
    11 rijen zijn geselecteerd.
    

    Kind regards
    Rob.

Maybe you are looking for