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

¡¾Ð¡Ð¡ÎÊÌ⼯½õ13Ö® ¹ØÓÚ·Ö×é¼Ó˳ÐòºÅµÄSQLд·¨¡¿


/*
Ô­±í£º  
thid      other  
a              1  
a              1  
b              0  
b              0  
b              0  
c              2    
c              2  
Ï£Íû±ä³É£º  
thid      other  
a              1  
a              2  
b              0  
b              1  
b              2  
c              2    
c              3  
*/
if OBJECT_ID('tb') is not null
drop table tb 
go
create table tb (id varchar(10) ,value int)
insert tb select 
'a'  ,            1  union all select 
'a'  ,            1  union all select
'b'  ,            0  union all select
'b'  ,            0  union all select
'b'  ,            0  union all select
'c'  ,            2  union all select 
'c'  ,   &nb


Ïà¹ØÎĵµ£º

SQL Server 2005: Recursive Hierarchies to XML

Suppose we have a recursive hierarchy stored in a relational database and we want to write it to XML.  This might be for a variety of reasons – e.g. as a pre-cached input to a UI control, to export to another system using a pre-defined format, etc.
 
In SQL Server 2000, in order to ......

SQL serverÑ­»·ÖÐÿ¸ôÒ»¶Îʱ¼ä,ÔËÐÐÒ»´ÎÓï¾ä

×î½ü×öÒ»¸öÏîÄ¿,˵ÆðÀ´±È½Ï¶ñ,ÊÇ´ÓÁíÒ»¸ö±íÖжÁÈ¡Êý¾ÝË͵½Õâ¸ö±íÖÐ.¶øÇÒÒªÓô¥·¢Æ÷Ñ­»·ÕâЩÄÚÈÝÔÙ·¢³öÈ¥.
¿ÉÊÇÈç¹ûÕâ¸öÊý¾ÝÁ¿ºÜ´óµÄ»°,»áÒ»ÏÂ×Ó¹ÒËÀ.ËùÒÔ¾ÍÏëµ½ÁË.Äܲ»ÄÜ,ÿ´ÎÎÒ´«Ò»µã,¸ô¼¸ÃëÔÙËÍÒ»µã.
ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄÀý×Ó
declare @i int
set @i=1
while @i<101
begin
insert into Cname ([name],csex,Number) ......

SQL³£Ó÷ÖÒ³µÄ°ì·¨

SQL³£Ó÷ÖÒ³µÄ°ì·¨:
±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º 
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
  (SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
  from ±íÃû
  ORDER BY ID))
  ORDER BY ID
//×Ô ......

SQL Server 2000 Java¿ª·¢Öе±Ç°Èͮ򵀫¦Àí

1¡¢ÔÚÊý¾Ý¿â½¨±íµÄʱºò×Ö¶ÎÖ±½ÓÉèÖÃΪDATETIMEÀàÐÍ£»
2¡¢Ö´ÐвåÈëµÄʱºòʹÓÃÈçÏÂÓï¾ä£º
PreparedStatement pstmt = conn.prepareStatement("insert into guestbook(gst_user,gst_title,gst_content,gst_ip,gst_time) values(?,?,?,?,getdate())");
3¡¢Òª°ÑÈÕÆÚ´ÓÊý¾Ý¿âÖÐÈ¡³ö£¬Ö´ÐÐÈçÏÂÓï¾ä£º
     ......

sqlÓï¾ä

select *from student
select student_id from student
select student_id ,student_name from student
select student_id student_name from student  ½«student_name ×÷Ϊstudent_idµÄ±ðÃû´¦Àí
È磺   select student_id a from student
 select a=student_id from student
´Óstudent±íÖзֱð¼ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ