質問

かの方法でご使用になることをモデルと取得する階層情報をデータベース?

役に立ちましたか?

解決

最終的な作品をここに書かれていたジCelkoを手がけて入しているというのジョー Celkoの木の階層アプリケーションのためのSmarties.

彼の好きなと呼ばれる演出です。紹介の作品につきま こちらの

他のヒント

私のように修正予約限定のツリーのフォーカストラバーサルアルゴリズムです。この手法は簡単に扱えるクエリのツリーが表示されます:

ものの一覧のリンクが多いので、私からコピーされZend枠組みをサポートに対するコミットメント投稿者専用ホームページに掲載しい投稿ローランMelmouxで淳05,2007年15:52).

多くのリンクは語agnostic:

ある2つの表現とアルゴリズムを代表する階層構造データベース:

  • 入れ子のセットとしても知られる修正予約限定のツリーのフォーカストラバーサルアルゴリズム
  • 隣接リストモデル

この説明はこちら

ここにはあるようなリンクだと:

隣接リストモデル

入れ子のセット

Graphes

クラス

ネストを設定しDBツリー Adodb

訪問のモデルADOdb

PEAR::DB_NestedSet

PEAR::ツリー

nstrees

何が最良の方法はhierachyがSQLデータベース?汎用、携帯用技術?

このようなhierachyは、読みがなを完全に対応します。ということかその家族ます。

こちらはうってはならないものとします:

create table person (
person_id integer autoincrement primary key,
name      varchar(255) not null,
dob       date,
mother    integer,
father    integer
);

挿入データのようになります:

person_id   name      dob       mother father  
1           Pops      1900/1/1   null   null  
2           Grandma   1903/2/4   null   null  
3           Dad       1925/4/2   2      1  
4           Uncle Kev 1927/3/3   2      1
5           Cuz Dave  1953/7/8   null   4
6           Billy     1954/8/1   null   3

代わりに、分割しておノードと関係の二つです。

create table person (
person_id integer autoincrement primary key,
name      varchar(255) not null,
dob       date
);

create table ancestor (
ancestor_id   integer,
descendant_id integer,
distance      integer
);

データの作成のようになります:

person_id   name      dob       
1           Pops      1900/1/1  
2           Grandma   1903/2/4   
3           Dad       1925/4/2   
4           Uncle Kev 1927/3/3
5           Cuz Dave  1953/7/8   
6           Billy     1954/8/1   

ancestor_id  descendant_id  distance
1            1              0
2            2              0
3            3              0
4            4              0
5            5              0
6            6              0
1            3              1
2            3              1
1            4              1
2            4              1
1            5              2
2            5              2
4            5              1
1            6              2
2            6              2
3            6              1

だができる任意のクエリがない為、テーブルに戻しそのものような出来事が起きないようにとがございましたheirachyと同じ行としてのノードです。

た祖父母?

select * from person where person_id in 
    (select descendant_id from ancestor where distance=2);

すべての子孫:

select * from person where person_id in 
    (select descendant_id from ancestor 
    where ancestor_id=1 and distance>0);

人uncles?

select decendant_id uncle from ancestor 
    where distance=1 and ancestor_id in 
    (select ancestor_id from ancestor 
        where distance=2 and not exists
        (select ancestor_id from ancestor 
        where distance=1 and ancestor_id=uncle)
    )

を回避するために、すべての問題の接合テーブル自体を経由のサブクエリは、共通の制限は16subsuqeries.

トラブルは、維持のために上位のテーブルのようなハード-ベストで保存されている。

もちろん、今年も同意できないとのジ.うな使用している場合は、大きな階層構造のような会社組織です。参加できる/休暇、会社に変更通報ラインなどの...維持の"距離"が大きな問題が維持つテーブルのデータです。

このクエリー(SQL Server2005年以上)または、完全にラインのいずれかの者の計算にある階層のすみが必要で単一テーブルのユーザ情報です。への組み換えができず子供の関係です。

--Create table of dummy data
create table #person (
personID integer IDENTITY(1,1) NOT NULL,
name      varchar(255) not null,
dob       date,
father    integer
);

INSERT INTO #person(name,dob,father)Values('Pops','1900/1/1',NULL);  
INSERT INTO #person(name,dob,father)Values('Grandma','1903/2/4',null);
INSERT INTO #person(name,dob,father)Values('Dad','1925/4/2',1);
INSERT INTO #person(name,dob,father)Values('Uncle Kev','1927/3/3',1);
INSERT INTO #person(name,dob,father)Values('Cuz Dave','1953/7/8',4);
INSERT INTO #person(name,dob,father)Values('Billy','1954/8/1',3);

DECLARE @OldestPerson INT; 
SET @OldestPerson = 1; -- Set this value to the ID of the oldest person in the family

WITH PersonHierarchy (personID,Name,dob,father, HierarchyLevel) AS
(
   SELECT
      personID
      ,Name
      ,dob
      ,father,
      1 as HierarchyLevel
   FROM #person
   WHERE personID = @OldestPerson

   UNION ALL

   SELECT
    e.personID,
      e.Name,
      e.dob,
      e.father,
      eh.HierarchyLevel + 1 AS HierarchyLevel
   FROM #person e
      INNER JOIN PersonHierarchy eh ON
         e.father = eh.personID
)

SELECT *
FROM PersonHierarchy
ORDER BY HierarchyLevel, father;

DROP TABLE #person;

参考:SQL Server2008を紹介する新しい HierarchyID データタイプのためにこのような状況です。らすのは上の"木"のお列に座,横と縦方向に配置します。

Oracle:のを選---開始。接続する

Oracleには、延長を選択できるようにツリーに基づく検索。かまさにSQLサーバーが類似す。

このクエリーにトラバーステーブルのネス関係を保存 親会子ども 列あります。

select * from my_table
    start with parent = :TOP
    connect by prior child = parent;

http://www.adp-gmbh.ch/ora/sql/connect_by.html

もしかしこのtechinques使用し、マークハリソン:

二つのテーブルのデータのその他のhierarchichal情報(person_id,parent_id[,mother_id])場合、PKのこのテーブルはperson_id、単純なツリーの唯一の親会社によるノード(ある意味でこの場合、その他の場合のように会計の勘定)

このhiarchyテーブルでtransversedによる再帰的手続きがある場合やDBサポートしている文章のように選---事前(Oracle).

その他の仕あがわかっている場合は、それを最大深の階層にしたいデータmantainはモーバイルコンピューティングテーブルの列のレベルの階層

また同時実施しましたツリーコンポーネントのための [fleXive] 使用メソッドは、入れ子のセットツリーモデルアプローチによるtharkunから MySQL docsに入ります。

加速もの(幅)を使用していました プロジェクトのフォローアップで使用した最大値はトップレベルの権限を挿入するとノードの移動付加すべての左右の値です。値を左右については決算の範囲にノードによる3undをご利用 内部 第三として境界の新しいノードです。

Javaコード例では見られる こちらの.

使用している場合は、SQL Server2005年その後 このリンク ついて説明を取得階層データです。

共通のテーブル表現(CTEs可お友達まで快適しています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top