Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

sqlÓï¾ä»ñȡҶ×Ó½Úµã

±í½á¹¹ Ϊ
id parentid name
1    0
2    0
3    1
4    3
5    2
ÊäÈë0ÏÖÔÚÏëµÃµ½
4 5
Ò²¾ÍÊÇ»ñȡҶ×ӽڵ㣬¸ÄÔõôʵÏÖ£¿ лл

http://blog.csdn.net/wufeng4552/archive/2009/09/30/4619995.aspx

ÎÒÒªµÄÊÇÒ¶×ӽڵ㣬¾ÍÊÇ×îµ×²ãµÄ½Úµã

0 µÃµ½4,5 ?

ÒýÓÃ
http://blog.csdn.net/wufeng4552/archive/2009/09/30/4619995.aspx

Õâ¸öºÃ

BOM¡¡¾«»ª

¶Ô 0 µÃµ½ 4 5

SQL code:
-->Title:Generating test data
-->Author:wufeng4552
-->Date :2009-09-30 14:27:56

if not object_id('tb') is null
drop table tb
Go
Create table tb([id] int,[parentid] int,[name] varchar(10))
Insert tb
select 1,0,null union all
select 2,0,null union all
select 3,1,null union all
select 4,3,null union all
select 5,2,null
Go
-->Title:²éÕÒÖ¸¶¨節點ϵÄ×Ó結點
if object_id('Uf_GetChildID')is not null drop function Uf_GetChildID
go
create function Uf_GetChildID(@ParentID int)
returns @t table(ID int)
as
begin
insert @t select ID from tb where ParentID=@ParentID
while @@rowcount<>0
begin
insert @t select a.ID from tb a inner join @t b
on a.ParentID=b.id and
not exists(select 1 from @t where id=a.id)


Ïà¹ØÎÊ´ð£º

ÈçºÎÓÃc#£¬sql2000 ¿ª·¢c/sÏµĹ¤×÷Á÷£¿

±¾ÈËc#ÐÂÊÖ ¿ÉÊÇÒªÇóÒªÓÃc# £¬sql2000¿ª·¢c/sµÄ¹¤×÷Á÷£¬Ò»Í·ÎíË®£¬Çë´ó¼Ò°ïæ°ï棬¸øµã˼·£¬ËµµÄÔ¼¾ßÌåÔ½ºÃ£¬ÎÒÒ²ºÃÍùÄǸö·½ÃæÈ¥Ñ§Ï°
http://www.hxzi.com/view/61402.html
B/S°æµÄ£¬»ù±¾Ë¼ÏëÓ¦¸Ã²î²»¶àµÄ¡£¡£ ......

sql ʱ¼äÎÊÌâ

sql table±íÓиöÎı¾ÀàÐ͵Äa×ֶΣ¬´æ´¢µÄÄÚÈÝÈ«²¿ÊÇÊý×Ö£¬ÀýÈç2009001£¬2008578ÕâÑùµÄ¸ñʽ£»b×Ö¶ÎÎı¾ÀàÐÍ£¬´æµÄÒ²ÊÇÊý×ÖÀýÈç 001£¬123
aspÀïÃæ strday=100£¬strb=001

ÎÒÏë¶Á³ö£¬´Óa×ֶεÄÊý×Ö°´´óµ½Ð¡µÄË ......

ÇóSQL£¿

´ó¼ÒºÃ£¬ÇëÎÊÔÚ±íMÖÐÓÐ×ֶΣºa b c d e 
ÎÒÏë²é³öÆäÖÐÂú×ãÏÂÃæÈÎÒâÒ»ÏîµÄÊý¾Ý£¬1.×Ö¶Îa µÄÖµ²»ÊÇ ¡®Êé»ò±Ê»ò±¾¡¯ÖÐÈÎÒ»£¬2.aΪÊéµÄʱºò×Ö¶Îb,cÊÇ¿Õ;3.µ±aֵΪ±ÊµÄʱºòdÊÇ¿Õ;4.µ±aΪ±¾µÄʱºòb,d,e¶¼ÊÇ¿Õ;5.È ......

sql²éѯÒÉÎÊ

±íÖа´datadate,tradeidΪÖ÷¼ü£¬Ò²¾ÍÊÇ˵tradeid»áÖØ¸´³öÏÖÔÚ²»Í¬ÌìÖУ¬Í¬Ò»ÌìµÄtradeidÊDz»Í¬µÄ¡£ÏÖÔÚÎÒÏ£Íûȡһ¶Îʱ¼ä·¶Î§ÄÚ²»Öظ´µÄtradeid£¬ÇÒֻҪÿ¸ötradeidµÄ×îºóÒ»´Î³öÏÖµÄÄÇÌõ¡£sqlÓï¾ä¸ÃÔõôд

£º ......

ÇósqlÎÄ

ÇóA != 1 and B != 2 ÒÔÍâµÄ¼Ç¼
a!=1 and b!=2 ÒÔÍ⣿

ÄÇÆñ²»ÊÇa=1»òÕßb=2µÄÕâÖÖÇé¿öô

select * from table where a = 1 or b = 2

Èç¹ûÊÇA != 1 and B != 2µÄ»°
select * from table where a ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ