±í½á¹¹ÈçÏ id parentid name 1 0 a 2 1 aa 3 0 b 4 1 ab .. parentid=0Ϊ¸ù½Úµã,parentid=id´ú±íÊÇËûµÄ×Ó½Úµã,Ö»ÓÐÒ»²ã¸¸×Ó¹ØÏµ ÎÒÏëÏÔʾΪ¸¸-ËùÓеĶù×ÓÕâÖÖÅÅÐò,²»ÖªÈçºÎд? ÅÅÐòºó: 1 0 a 3 1 aa 4 1 ab 2 0 b
Çë¸ßÊÖÖ¸µãÒ»¶þ.
SQL code: --> Title : Generating test data [tb] --> Author : --> Date : 2009-11-23 15:33:58 if object_id('[tb]') is not null drop table [tb] go create table [tb] (id int,parentid int,name nvarchar(4)) insert into [tb] select 1,0,'a' union all select 2,1,'aa' union all select 3,0,'b' union all select 4,1,'ab' select * from tb order by case when parentid=0 then id else parentid end /* id parentid name ----------- ----------- ---- 1 0 a 2 1 aa 4 1 ab 3 0 b
(4 個資ÁÏÁÐÊܵ½Ó°響)
*/
SQL code
Code highlighting produced by Actipro CodeHighlighter