Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to take sqrt in sqlite

Tags:

php

sqlite

This is the query of PHP using MySQL. can anyone please convert this query to sqlite query?

Query:

select SQRT(POW(latitude, 2) + POW(longitude, 2)) *110 as dist from route

Best Regards, Thanks

like image 528
Naveed Avatar asked Jul 30 '10 04:07

Naveed


2 Answers

I have done it with the help of "pascal".

The query becomes:

SELECT
    * 
FROM
    (
        SELECT 
            temperature,
            climate,
            temperatureTime,
            photoURL,
            (((latitude - 37.331689) * (latitude - 37.331689)) + (longitude - (-122.030731)) * (longitude - (-122.030731))) * (110 * 110) AS dist 
        FROM 
            weather
    )
    AS tab 
WHERE 
    tab.dist <= (1.0 * 1.0); 

This query is used to find out the nearest coordinates of locations around me within 1 KM.

like image 150
Naveed Avatar answered Nov 02 '22 12:11

Naveed


It's trivial to register PHP's sqrt with sqlite_create_function.

sqlite_create_function($sqlite_db, "sqrt", "sqrt", 1);

Without registering, you can use:

php('sqrt', value);
like image 43
Matthew Flaschen Avatar answered Nov 02 '22 12:11

Matthew Flaschen