Calculating the lat and lon from given kilometer - latitude-longitude

I am trying to calculate the latitude and longitude from the given radius. Eg: If my latitude and longitude is 1.234 and 2.345. 5KM is the radius. What will the latitude and longitude after 5KM ? I have no idea how to calculate this. Please help me out.

Related

SQL Query for sum of columns based on trip

I am having below table and here I need to calculate the total distance travelled. For Ex:
enter image description here
Here I need to calculate the total trip distance its covered from Start Location to end location. like From A to A total distance is 55 km. From E to E 41 KM. Not sure how to calculate it in SQL. Can you any one help me to give some idea to fix this.
Regards
Anand

Time Series Rolling Window Mean with Nearest Points

I want to implement a function in that could compute rolling mean and median on a time series data using nearest neighbour points and I am wondering how I can do it in SQL.
To illustrate what I am trying to do:
Assuming I have
data containing information on parked vehicles across all carparks in USA everyday (From 2022-01-01 till 2022-07-18) as well as their exact parking location (latitude longitude) and the cost of the vehicle.
Vehicle Tracking System containing 10 unique Tracker ID, Date Installed, its latitude and longitude in a particular carpark
Example of the first data:
Date, vehicle ID, cost of vehicle (in $), latitude, longitude
2022-07-18, 1, $4000, 3.15, 100.15
2022-07-18, 2, $3000, 3.11, 100.13
2022-07-17, 3, $5000, 3.12, 100.10
...
Example of second data:
Tracker ID, Date Installed, latitude, longitude
A, 2022-07-18, 3.14, 100.12
B, 2022-07-20, 5.10, 105.14
For each Tracker, I want to know what is the mean and median cost of the nearest 5 vehicles parked within 1km of its vicinity based on the past 5 days parking data, as well as past 10 days parking data from its date of Installation (Vehicles can freely move in and out of a carpark anytime)
Example of how my output should be:
Tracker ID, Mean_Cost_5, Median_Cost_5, Mean_Cost_10, Median_Cost_10
Tracker 1, $4000, $4000, $7000, $5000 (Using carpark data from 5 and 10 days before 2022-07-18)
This should be done for each of the 10 Trackers.
How can I implement it in SQL?

SQL Weighted Average - Population & Income

I am trying to find the average household income while using a weighted average. I have a data source of ZIP codes with the total population and the average household income. I want to be able to select multiple ZIP codes and still pull an accurate average household income.
Can I use SQL to pull a weighted average like this?
ZIP
TOTAL_POP
AVG_HH_INC
12345
130350
66000
54321
55750
78000
44668
17300
89000
If you want the overall average, then use arithmetic:
select sum(total_pop * avg_hh_inc) / sunm(total_pop)
from t;
Note: If the values are stored as 4-byte integers, then this runs the risk of overflow. Just use a different numeric representation if that is an issue.

Select objects within radius using longitude and latitude [duplicate]

This question already has answers here:
SQL Query for Performing Radius Search based on Latitude Longitude
(4 answers)
Distance Calculation with huge SQL Server database
(1 answer)
Closed 9 years ago.
I wonder how I can create a query and select objects that are located within a radius of 50 km.
The information I can use is Longitude and latitude for every object. I would like to set my own location in the query and calculate the objects distance to my position based on its coordinates.
Assuming you're using a geography type, which you should be, use STDistance - see http://technet.microsoft.com/en-us/library/bb933808.aspx
select *
from yourtable
where place.STDistance(#myposition)<50000

SQL - Which data type represents percentages well?

In SQL I am looking at decimal and float. Float says it is an approximation. I need to store percentages. They don't have to be very large or small. Some examples are
60.2
40
Which data type should I use?
decimal(x,y)
x is the total number of digits you want to be able to represent
y is the total number of digits after the decimal point that you want to be able to represent