Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # ABS, RMS, DIST
  2. # 절대값, 제곱 평균 제곱근, 거리
  3.  
  4. DROP TABLE IF EXISTS location_1d;
  5. CREATE TABLE location_1d (
  6. x1 integer
  7. , x2 integer
  8. );
  9.  
  10. INSERT INTO location_1d
  11. VALUES
  12. ( 5 , 10)
  13. , (10 , 5)
  14. , (-2 , 4)
  15. , ( 3 , 3)
  16. , ( 0 , 1)
  17. ;
  18.  
  19. DROP TABLE IF EXISTS location_2d;
  20. CREATE TABLE location_2d (
  21. x1 integer
  22. , y1 integer
  23. , x2 integer
  24. , y2 integer
  25. );
  26.  
  27. INSERT INTO location_2d
  28. VALUES
  29. (0, 0, 2, 2)
  30. , (3, 5, 1, 2)
  31. , (5, 3, 2, 1)
  32. ;
  33.  
  34. ## ABS, RMS
  35. ## 절대값 - abs, 제곱- power, 제곱근 - sqrt
  36. select
  37. abs(x1-x2) AS abs
  38. , sqrt(power(x1-x2, 2)) AS rms
  39. FROM location_1d
  40. ;
  41.  
  42. ## Dist
  43. ## 유클리드 거리구하기
  44. SELECT
  45. sqrt(power(x1-x2, 2)) + sqrt(power(y1-y2, 2)) AS dist
  46. FROM location_2d
  47. ;
  48.  
  49. #위 내용은 SQL 레시피 (한빛미디어)를 참고하였습니다.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement