challenge データの整列

(x, y) の座標情報を以下の2種類の方法で整列する機能を実現してください。

  • (x, y) の辞書順(まず x で昇順に整列して、x が同じデータに対して y で昇順に整列する)
  • (0, 0) からの距離の昇順

データの表現方法はタプルなり構造体/オブジェクトなり各自で適当に選んで下さい。

Posted feedbacks - SQL

#5889 の答えとほとんど変わらないけど。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
--テーブル:POINTS
create table POINTS (
  X number(10),
  Y number(10)
);
--データ
insert into POINTS values (-2, 2);
insert into POINTS values (3, 2);
insert into POINTS values (1, -5);
insert into POINTS values (4, 5);
insert into POINTS values (1, -2);
--辞書順
select * from POINTS order by X, Y;
--距離順
select * from POINTS order by x*x + y*y;

Index

Feed

Other

Link

Pathtraq

loading...