Calculate the distance using values from table

Based on the coordinates of two points A(x1,y1) and B(x2,y2) and x 1, x 2, y1, y2 are columns of the table to a table, I need a query (function?) to calculate the distance between these two points of each line of the table...
Table:
NRCRT (PK) X 1 X 2 Y1 Y2
1 10 6 2 4
2 1 3 0 5

the mathematical formula is:
http://www.mathwarehouse.com/algebra/distance_formula/images/distance-formula-image.jpg

It is complex to me, but maybe someone can help me...

Wintermute3190 wrote:
Œuvres, but:
DISTANCE_BETWEEN
4.47213595499957939281834733746255247088
5.3851648071345040312507104915403295563

How to set to 5,38 just and 4.47

CYCLE of use or function TRUNC

SQL> WITH test_tab AS
  2       (SELECT 1 nrcrt, 10 x1, 6 x2, 2 y1, 4 y2
  3          FROM DUAL
  4        UNION ALL
  5        SELECT 2, 1, 3, 0, 5
  6          FROM DUAL)
  7  SELECT nrcrt,
  8         TRUNC(SQRT ((POWER ((x2 - x1), 2) + POWER ((y2 - y1), 2)
  9               )),2) distance_between
 10    FROM test_tab
 11  /

     NRCRT DISTANCE_BETWEEN
---------- ----------------
         1             4.47
         2             5.38

SQL> WITH test_tab AS
  2       (SELECT 1 nrcrt, 10 x1, 6 x2, 2 y1, 4 y2
  3          FROM DUAL
  4        UNION ALL
  5        SELECT 2, 1, 3, 0, 5
  6          FROM DUAL)
  7  SELECT nrcrt,
  8         ROUND(SQRT ((POWER ((x2 - x1), 2) + POWER ((y2 - y1), 2)
  9               )),2) distance_between
 10    FROM test_tab
 11  /

     NRCRT DISTANCE_BETWEEN
---------- ----------------
         1             4.47
         2             5.39

Notice the difference in the result. Use the one that works best for you.

Kind regards
JO

Tags: Database

Similar Questions

  • Calculate the space used in the database!

    Hi all

    I can calculate the space used by using one of the following ways:

    1. determine the size allocated by issuing

    SELECT SUM(d.bytes/1024/1024/1024)
    FROM dba_data_files;

    2 calculate the free space by issuing

    SELECT SUM(bytes/1024/1024/1024)
    from dba_free_space;

    Space used will be the value of the first statement - value of the second statement. This is manually!

    Is it possible to combine these two queries?

    Thank you!

    Dan.

    You can certainly combine queries

    SELECT (allocated.bytes - free.bytes )/1024/1024/1024 used_gb
      FROM (select sum(bytes) bytes from dba_data_files) allocated,
          (select sum(bytes) bytes from dba_free_space) free
    

    Normally, you could group tablespace as well.

    But if you want just the amount of space used, it is probably easier to just

    SELECT sum(bytes)/1024/1024/1024 used_gb
      FROM dba_segments
    

    Justin

  • How to pass a value from table in to another using java-oracle script: apex 5.0

    Hello

    Step 1:

    Two Table (product, product 2)

    Created an IR where all data are from Table Product

    -> a cell in the column is editable.

    Step 2:

    Whenever the user change certain values of cell and click on the button set to day then cell value must also be updated in the table leader2.

    -> entire product line (table) must be inserted into the product 2 (table) with update of the cell value.

    JS:

    var arr_f01 = [];

    () $("input[name='f01']").each

    function() {}

    If ($(this).) Val() > 0)

    {

    arr_f01.push ($(this).) Val());

    }

    });

    (apex). Server.Process

    "Update".

    {f01: arr_f01,}

    {dataType: "text", success: function (pData) {alert ("' data inserted into the Table Product");}}

    } }

    );

    Thank you.

    Hi Dominique,.

    Pranav.Shah wrote:

    Hello

    Step 1:

    Two Table (product, product 2)

    Created an IR where all data are from Table Product

    --> A cell in the column is editable.

    Step 2:

    Whenever the user change certain values of cell and click on the button set to day then cell value must also be updated in the table leader2.

    ---> Whole product line (table) must be inserted into the product 2 (table) with update of the cell value.

    JS:

    var arr_f01 = [];

    () $("input[name='f01']").each

    function() {}

    If ($(this).) Val() > 0)

    {

    arr_f01.push ($(this).) Val());

    }

    });

    (apex). Server.Process

    "Update".

    {f01: arr_f01,}

    {the data type: 'text', success: function (pData) {alert (' ' data inserted into the Table Product ');}}

    } }

    );

    Thank you.

    Follow the steps below.

    Step 1: Give static id to the other columns in your interactive report

    Attributes of the region-> column-> Id static definition

    Step 2: change your Javascript code to read values of other columns

    check the line no 8, in this way, you can read the value of other columns and push that in table

    This is the static id of the column I given EMPNO.

    do the same for the other columns you want to insert.

    var arr_f01 = [];
    var arr_f02 = [];
    var empno;
    $("input[name='f01']").each(
    function() {
    if($(this).val() > 0)
    {
      empno = $(this).closest('tr').children('td[headers="EMPNO"]').text();
      arr_f01.push($(this).val());
      arr_f02.push(empno);
    }
    });
    
    apex.server.process (
      "Update"
    , {  f01: arr_f01, f02: arr_f02
      }
    , { dataType: 'text',success: function(pData){alert('Data Inserted in Product Table');
    } }
    );
    

    Step 3: use tables in your ajax process to insert the record., replace your table name and the columns

    begin
    for i in 1..apex_application.g_f01.count loop
    insert into test(A,B) values (APEX_APPLICATION.G_F02(i),APEX_APPLICATION.G_F01(i));
    commit;
    end loop;
    end;
    

    Hope this helps you,

    Kind regards

    Jitendra

  • Need to use values from the first query in other queris to the data model

    Hello
    Here is my requirement-

    I use the data model to run multiple queries. The first query, I get 10 records. Now, I want to use these 10 records in the second query to get my final result. I am not able to use the sub query as the two motions are quite long and complex.

    Select distinct Bishop of emp

    Select empno, emp where Bishop in (: Bishop)

    I can't use: Bishop because it will give only the last value stored at Archbishop. Is it possible to be able to use all the values from the first query in the second query using the data model?

    Hello

    Are you sure that you have your "dataStructure" configured correctly? Try this simple example:

                                                                          
    

    Hope this helps

    Andy

  • Measure the distance using color sensor 2.0

    Hi all!

    I would like to know if there is a way to measure the distance of an object using the color sensor that comes with the Mindstorms 2.0. I am gaining a few conferences of the sensor, but I don't know how to convert these values to distance.

    Any reference or a link would be appreciated!

    Thank you!

    Hi fran_jo,

    Here is an article which offers a good method to calculate the exact values of scaling to convert measures of intensity at a distance: http://www.hitechnic.com/blog/eopd-sensor/eopd-how-to-measure-distance/.  Do not forget that this relates to a third party of sensor, but the concepts should always be applied.

    Also note that the color sensor is affected by ambient light.  You can try to use a 2nd sensor to take account of all the ambient light.  What you trying to accomplish with this application?  Is there a reason that you are not using the ultrasonic sensor?

  • How to format a cell to calculate the distance based on names of cities in the other two cells

    I am using 3.6.1 numbers to display distances in Miles or Km in column 3 based on the names of the cities in columns 1 and 2

    For example:

    "Boston' appears in the cell"A1"and"New York"in cell"B1. "  I would like that the cell "C1" then automatically read "215 Miles.

    I could not find a way to do it. Any help would be appreciated. Thank you in advance.

    Hi Nicolas,.

    Which you will store the information needed for the numbers compute these results?

    If she wants to be a direct calculation of the shortest distance, you will need the geographical location of each of the two cities, as well as an algorithm/formula for the calculation of the circle distance between these two places. Boston-New York, is about 190 miles.

    On distance (215 miles) of driving, the calculations are a bit more complicated. They require access to a wide range of data including a "route map" for the area that you want to include, then an algorithm that can look up cities, determine a route between them, find the distance of conduct for each section of this road and add them to the top.

    If you place a strict limit on the number of cities and have access to networks "driving distance" which were (and maybe still) included with the paper maps printed of gas stations or AAA (to the United States), CAA (Canada), the AA (in Britain) and other organizations to motorist elsewhere in the world, you might be able to manage it with one or more lookup tables and a search feature appropriate in column C.

    Otherwise, you may incur development of Google (or one of several others) team to reinvent the wheel, so to speak, and provide you a stand-alone application to do this.

    Or you can choose to use a more suitable and existing tool. Some choices are MapQuest, OpenStreetMap, Bing Maps, Google Maps, or maps (Apple) (included in recent versions of Mac OS X).

    Kind regards

    Barry

  • Calculate the sum of values of 2 where Clauses

    Hi, sorry to trouble, I have all the data in a database or anything like that, just to think about some of the work I have to do, trying to get ahead. I was wondering how i would be the sum of the values in a column, but with 2 where clauses. By example, if I wanted to the sum of all the values until 18:00 in 1 column and all the after 18:00 for 1 day how I would write this out.

    I don't know how to write separately, i.e.

    select name, sum(values) as after6
    from table
    where time > '18:00'
    group by name;
    

    select name, sum(values) as upto6
    from table
    where time < '18:00'
    group by name;
    

    How can I combine these columns after6 and upto6 next to each other.

    If someone could please advise.

    Thanks in advance

    Select the name,

    sum (case when time > 18:00 ' then 0 otherwise end of values) as after6,.

    sum (case when time< '18:00'="" then="" values="" else="" 0="" end)="" as="">

    table

    Group by name;

    ----

    Ramin Hashimzade

  • Insert the problem using a SELECT table with an index by TRUNC function

    I came across this problem when you try to insert a select query, select returns the correct results, but when you try to insert the results into a table, the results are different. I found a work around by forcing a selection order, but surely this is a bug in Oracle as how the value of select statements may differ from the insert?

    Platform: Windows Server 2008 R2
    11.2.3 Oracle Enterprise Edition
    (I've not tried to reproduce this on other versions)

    Here are the scripts to create the two tables and the data source:
    CREATE TABLE source_data
    (
      ID                 NUMBER(2),
      COUNT_DATE       DATE
    );
    
    CREATE INDEX IN_SOURCE_DATA ON SOURCE_DATA (TRUNC(count_date, 'MM'));
    
    INSERT INTO source_data VALUES (1, TO_DATE('20120101', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120102', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120103', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120201', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120202', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120203', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120301', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120302', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120303', 'YYYYMMDD'));
    
    CREATE TABLE result_data
    (
      ID                 NUMBER(2),
      COUNT_DATE       DATE
    );
    Now, execute the select statement:
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM')
    You should get the following:
    1     2012/02/01
    1     2012/03/01
    1     2012/01/01
    Now insert in the table of results:
    INSERT INTO result_data
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM');
    Select the table, and you get:
    1     2012/03/01
    1     2012/03/01
    1     2012/03/01
    The most recent month is repeated for each line.

    Truncate your table and insert the following statement and results should now be correct:
    INSERT INTO result_data
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM')
    ORDER BY 1, 2;
    If someone has encountered this problem before, could you please let me know, I don't see what I make a mistake because the selection results are correct, they should not be different from what is being inserted.

    Published by: user11285442 on May 13, 2013 05:16

    Published by: user11285442 on May 13, 2013 06:15

    Most likely a bug in 11.2.0.3. I can reproduce on Red Hat Linux and AIX.

    You can perform a search on MOS to see if this is a known bug (very likely), if not then you have a pretty simple test box to open a SR with.

    John

  • How to fill the area of the bean with values from database

    I have a box of bean shaped which act as last autocomplete, I want to fill it with dynamic values of database, any help will be appreciated.
    http://Forms.PJC.Bean.over-blog.com/article-16369664.html "It is the example that I am"

    Best regards.

    An example with the EMP table:

    DECLARE
      cursor cur is select empno,ename from emp;
    BEGIN
      -- initialise the ComboBox twin values --
      for c in cur loop
       if c.empno is not null then
        Set_Custom_Property('BL.BEAN',1,'ADD_TWIN',c.empno||','||c.ename);
       else
        Set_Custom_Property('BL.BEAN',1,'ADD_TWIN_NULL',c.empno||','||c.ename);
       end if ;
      end loop;
      Set_Custom_Property('BL.BEAN',1,'ADD_TWIN','[END_DATA]');
      Set_Custom_Property('BL.BEAN',1,'SET_ALIGNMENT','right');
    END;
    

    François

  • How to measure the distance using script

    Hello

    Is it possible to measure the distance of any document in photoshop using the measure tool, using the script. Below the steps required by me. Hope I'm clear in my communications.

    I've searched the forums, but couldn't find appropriate answers.

    1. open the Photoshop document

    2. allow the user to draw the line with measure tool

    3. the alert distance

    RGS

    Anish

    This only works with CS5 because it now uses the tool instead of a path rule. But it solves all the problems talked about in this thread and many other differences between the original function and the data in the info panel.

    It returns a custom with angle and length properties object if there is a rule tool line in the active document and not of the indefinite. I didn't know if the length must be a unitValue or number in the units of the rule settings. I went with number because the Panel info has different number of decimal places for the different units. And as the Panel assigned the corresponding graduation info per cent the length value is empty

    function getRulerToolLengthAndAngle() {}

    points of var = [];

    points. Start = [];

    points. End = [];

    var / / desc = new ActionDescriptor();

    Var ref = new ActionReference();

    ref.putProperty (charIDToTypeID ('Rprp'), charIDToTypeID ("RrPt"));

    ref.putEnumerated (charIDToTypeID ('Dcmn'), charIDToTypeID ('Ordn'), charIDToTypeID ('Trgt'));

    desc.putReference (charIDToTypeID ('null'), ref);

    var / / desc = executeAction (charIDToTypeID ('getd'), desc, DialogModes.NO);

    If (desc.hasKey (charIDToTypeID ('points'))) {}

    pointList var = desc.getList (charIDToTypeID ('points'));

    var startPointDesc = pointList.getObjectValue (0);

    points. Start.push (startPointDesc.getUnitDoubleValue (charIDToTypeID ('X')));

    points. Start.push (startPointDesc.getUnitDoubleValue (charIDToTypeID ('Y')));

    var endPointDesc = pointList.getObjectValue (2);

    points.end.push (endPointDesc.getUnitDoubleValue (charIDToTypeID ('X')));

    points.end.push (endPointDesc.getUnitDoubleValue (charIDToTypeID ('Y')));

    var RES = {};

    res.toString = function() {return "RulerTool news" ;};}

    Pointed var = points.start;

    var points.end = b;

    If (pointed [0]

    var a = Math.max(pointA[0],pointB[0]) - Math.min (pointed [0], b [0]);

    var o = Math.max(pointA[1],pointB[1]) - Math.min (pointed [1], b [1]);

    var ang = (180/Math.PI) * Math.atan2(o,a);

    If (pointed [1]< pointb[1]){//negative="">

    Ang = - ang;

    };

    Res.angle = ang.toFixed (1);

    } else {}

    var a = Math.max(pointA[1],pointB[1]) - Math.min (pointed [1], b [1]);

    var o = Math.max(pointA[0],pointB[0]) - Math.min (pointed [0], b [0]);

    var = 180-((180/Math.PI) Ang * Math.atan2 (a, o));

    If (pointed [1]< pointb[1]){//negative="">

    Ang = - ang;

    };

    Res.angle = ang.toFixed (1);

    }

    If (app.preferences.rulerUnits == Units.PERCENT) {}

    Res. Length = "";

    } else {}

    var c = Math.sqrt + ((a*a) (o * o));

    var length = new UnitValue (c, 'px');

    length.baseUnit = new UnitValue((1/app.activeDocument.resolution),'in');

    Switch (app.preferences.rulerUnits) {}

    case Units.PIXELS: res.length = length.as('px').toFixed (2); break;

    case Units.INCHES: res.length = length.as('in').toFixed (3); break;

    case Units.CM: res.length = length.as('cm').toFixed (2); break;

    case Units.MM: res.length = length.as('mm').toFixed (1); break;

    case Units.POINTS: res.length = length.as('pt').toFixed (1); break;

    case Units.PICAS: res.length = length.as('pc').toFixed (2); break;

    }

    }

    return res;

    }

    }

    var getRulerToolLengthAndAngle() = Info;

    If (info! = undefined) alert (' the ruler tool angle is: ' + info.angle +'\nThe length is: ' + info.length);

  • Calculate the space used by an individual/idebtifying partition in the partitions belonging to a partition - possible?

    Hello

    Using oracle 11.2.0.3 and have a partitioned table, some of the partitions use their own tablespace for to use WHERE user_segments but many partitions share the same tablespace.

    We wish to place each partition to a tablepsace of dedicatde and seek to identify the space used by a single partition.

    What is the best way to do this?

    See user_tatb_partitions ha snum_rows + blocks.

    Can see WHERE user_segments door secondary partition names.

    Is that a query can use for secondary idnentify belonging to a partition

    Thank you

    See halfway down the page below for SQL XML util to convert a string of high_value.

    http://OraStory.WordPress.com/2013/12/12/SQL-utils-using-XML/

  • Question about the order of evaluation of the clause WHERE CLAUSE when the Oracle OF the syntax used to join tables

    Hello

    Oracle version: 11.1.0.7.0 - 64 bit

    I read the documentation online at joins. The page is avialable here: joins at

    My question is about the join order of evaluation of the conditions in clause and the conditions of those

    are not the join conditions and are placed in the WHERE clause.

    Consider the following pseudocode

    SELECT

    T1. Col1,

    T2.Col1

    Of

    Table1 t1 LEFT OUTER JOIN table2 t2

    WE

    (condition_expression1)

    WHERE

    (condition_expression2)

    Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article?

    Thanks in advance,

    Hello

    dariyoosh wrote:

    Hello

    Oracle version: 11.1.0.7.0 - 64 bit

    I read the documentation online at joins. The page is avialable here: joins at

    My question is about the join order of evaluation of the conditions in clause and the conditions of those

    are not the join conditions and are placed in the WHERE clause.

    Consider the following pseudocode

    SELECT

    T1. Col1,

    T2.Col1

    Of

    Table1 t1 LEFT OUTER JOIN table2 t2

    WE

    (condition_expression1)

    WHERE

    (condition_expression2)

    Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article? ...

    The reverse is actually closer to the truth, but we can't really make general statements like that.

    SQL is not a language of the proceedings.  Looking at the code SQL, we could say that the code does, but we cannot say much about how that code it.  In other words, SQL is a language that describes the results you get, not the way to get them.

    The optimizer will do everything what he thinks is faster if it does not change the results.  If any order in which they are applied (in outer joins or CONNECT BY queries, for example), then think of the join is done first, and the value of the WHERE clause is applied to the result of the join.

    Here is a query looks very much like you posted:

    SELECT d.deptno

    e.ename, e.sal

    OF scott.dept d

    LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno

    WHERE e.sal > = 3000

    ORDER BY d.deptno

    ;

    Output:

    DEPTNO ENAME SAL

    ---------- ---------- ----------

    10 KING 5000

    20 FORD 3000

    20 3000 SCOTT

    The scott.dept table contains deptnos 30 and 40; Why are they not in the result set?  The query behaves as if the outer join is made first (production 15 rows), then the WHERE clause has been applied.  All lines with deptno = 30 had sals down han 3000 and all single line with deptno = 40 was NULL in the sal column, then these lines are excluded (as well as other lines of deptnos 10 and 20), and only 3 lines above are left.

  • Calculates the treatment field values 1 step behind

    I have a very long form created in Acrobat Pro (latest version).

    To simplify the problem, this is what is happening.

    I have text boxes on a form and the user will enter quantity and price in each row for the materials and form will calculate to multiply these values and give you the total for each product and at the end, add all the totals giving you your total final.

    T1 * P1 = T1

    T1 + T2... T40 plus Total cost of material

    Which works very well.

    I then the user enter the estimate and below this breakthrough for what is the cost of labour, which is the cost of equipment, which is taxes, and then the rest is profit. The cost of the equipment is simply copied to the Total cost of the above materials.

    However, the calculation is made to simply take so I need percentages thus:

    The total cost of materials / estimate = percentage

    This grave 1 step walk behind. As in, it has not calculated the first go-around. You must enter a value elsewhere on the form or if I generate a button "Calculate" it will then deal with it. It's like if we take the old value before the field has been dynamically updated.

    Link to the PDF is below, if you fill in the Qs and Ps see the Ts fill fine.

    Below on the left turns is the estimate that you need to enter. In doing so, you will see the % for material cost and profit are bad, if you change a value anywhere on the form, you will see that they are then the value that was already there.

    I hope that makes sense for a person, the calculated values are 1 step behind and I need to understand why and get that fixed.

    Link to the PDF document

    Also, if I do these fields % under the shape number and 2 decimal places, I get an avalanche of mistakes whenever I enter a new value somewhere on the form I think because he's trying to divide by a number of vacuum which get a NaN error and gives me a pop up that it does not match the required format. How can I disable this error? I need to limit it to 2 decimal places, or 3 actually, but don't have a ton of errors popup whenever the user starts to fill the form.

    It's a problem of calculation of classic field command. You need to go to Tools - Forms - change - other tasks - defined field calculation order and whole list in the order in which calculations occur. So if a field is dependent on the value of the field B, then it must be lower than him in the list.

  • calculate the deduction using the percentage and amount

    I have a dynamic form with three fields decimal:

    grossamount (grossamount)

    percentage of deduction (fwpercent)

    amount of the deduction (fwamount)

    I have the following scripts:

    Form1. #subform [0]. fwpercent::calculate - (FormCalc, client)

    fwamount/grossamount*100

    Form1. #subform [0]. fwamount::calculate - (FormCalc, client)

    grossamount*fwpercent/100

    I want to be able to change the amount or percentage and have it calculate the other, as shown in the scripts. If I open the form and taken in 100 for the gross amount, then 10 percent, the script works correctly, and 10 will be displayed in the w/h quantity. If I go to the fw amount field and replace it with 20, the percentage field still shows 10. the results are the same, if I make first, and then changes the percentage value but does not update if I do update percentage. This will only work for everything that I do everything first. I can't always fields depend on eachother whenever one of them is changed?

    changed for the scripts below and it works as expected:

    Form1. PaymentInfo.FederalWithholdingPercentage::exit - (JavaScript, client)

    FederalWithholding.rawValue=GrossAmount.rawValue*FederalWithholdingPercentage.rawValue/100;

    Form1. PaymentInfo.FederalWithholding::exit - (JavaScript, client)

    FederalWithholdingPercentage.rawValue=FederalWithholding.rawValue/GrossAmount.rawValue*100;

  • Select the list display value from a javascript function

    Hi all

    I have a list in tabular form, having a display value and return value.

    I use $x (statement) .value or $v (statement) for retreving return the value of the selection list in a javascript function.

    Can someone let me know how I can get the display of the selection list value in a javascript function? IM using Apex 3.2

    Thank you and best regards,
    Sandeep

Maybe you are looking for