当前位置:网站首页>leetcodeSQL:612. Nearest distance on plane

leetcodeSQL:612. Nearest distance on plane

2022-06-12 01:47:00 Review of the white speed Dragon King

 Insert picture description here
Ideas :
1. Add up the differences Descartes , And then calculate dis
2. use cast + decimal(15,2) Keep two decimal places order limit that will do

sql

# Write your MySQL query statement below
#  Find out the two different points and their examples 
#  use cast Keep a few decimal places 
select cast(dis as decimal(15,2)) shortest
from
(
    select p1.x x1, p1.y y1, p2.x x2, p2.y y2, round(sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y)), 2) dis
    from Point2D p1, Point2D p2
    where p1.x != p2.x or p1.y != p2.y
) t
order by shortest
limit 1

summary :
cast(var as decimal(15,x))

原网站

版权声明
本文为[Review of the white speed Dragon King]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011215436698.html