場所分雷-復習3

2166 ワード

2つの値の距離を計算


SELECT ABS(x1-x2) AS abs
     , SQRT(POWER(x1-x2,2)) AS rms
  FROM location_1d

これは、1次元ポイント間の距離を求めるクエリーです.
ABS:割引を計算する関数
POWER:二乗関数
SQRT:平方根を求める

2 D平面の上で2点の間の距離を求めます
SELECT SQRT(POWER(x1-x2, 2)+POWER(y1-y2,2)) AS dist
  FROM location_2d

これはピタゴラス式を適用してユークリッド距離を計算するクエリです.

計算日/時刻


SELECT user_id
     , register_stamp::timestamp AS register_stamp
     , DATEADD(hour, 1, register_stamp::timestamp) AS after_1_hour
     , DATEADD(minute, -30, register_stamp::timestamp) AS before_30_minutes
     
     , register_stamp::date AS register_date
     , DATEADD(day, 1, register_stamp::date) AS after_1_day
     , DATEADD(month, -1, register_stamp::date) AS before_1_month
  FROM mst_users_with_dates
SELECT user_id
     , CURRENT_DATE AS today
     , register_stamp::date AS register_date
     , CURRENT_DATE - register_stamp::date AS diff_days
  FROM mst_users_with_dates

会員登録日と現在の日付、会員登録日と生年月日の日付の違いを計算するクエリーです.
IPアドレスから4つの10進数部分のクエリを抽出
SELECT ip
     , CAST(SPLIT_PART(ip, '.', 1) AS integer) AS ip_part_1
     , CAST(SPLIT_PART(ip, '.', 2) AS integer) AS ip_part_2
     , CAST(SPLIT_PART(ip, '.', 3) AS integer) AS ip_part_3
     , CAST(SPLIT_PART(ip, '.', 4) AS integer) AS ip_part_4
  FROM (SELECT '192.168.0.1' AS ip) AS t