¡¾Ð¡Ð¡ÎÊÌ⼯½õ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
Ïà¹ØÎĵµ£º
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 ......
Ò»£ºSelectÓï¾ä£º
select ×Ö¶ÎÃû from ±íÃû where Ìõ¼þ order by ÅÅÐò
see:select distinct ´Ó¶à¸öÏàͬ×Ö¶ÎÖÐץΨһֵ
see:²éÕÒld_det_andy±íÖÐÓÐÊý¾Ýµ«ld_det_temp±íÖÐûÊý¾ÝµÄÊý¾Ý
select * from ld_det_a ......
DB2 SQL PL
SQL PLÊÇDB2ËùÖ§³ÖµÄ¹ý³Ì»¯ÓïÑÔ£¬ËüÊÇSQL/PSM±ê×¼µÄÒ»¸ö×Ó¼¯¡£Æä¸ù¾ÝÓ¦Ó÷¶Î§²»Í¬£¬ÓÖ·ÖΪInline SQL PL£¬Embeded SQL PLºÍCompiled SQL PL¡£
Inline SQL PL
ÊÊÓ÷¶Î§£º´¥·¢Æ÷¡¢º¯ÊýºÍ·½·¨£¬Ö§³Ö²¿·ÖSQL PL£¬Ê¹ÓÃʱҪעÒâһЩÏÞÖÆ
Óï·¨¹æÔò£ºBEGIN ATOMIC ... END
Embeded SQL PL
ÊÊÓ÷¶Î§£ºÇ¶Èëʽ£¬Åäº ......
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä:
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-nam ......
×î½ü×öÒ»¸öÏîÄ¿,˵ÆðÀ´±È½Ï¶ñ,ÊÇ´ÓÁíÒ»¸ö±íÖжÁÈ¡Êý¾ÝË͵½Õâ¸ö±íÖÐ.¶øÇÒÒªÓô¥·¢Æ÷Ñ»·ÕâЩÄÚÈÝÔÙ·¢³öÈ¥.
¿ÉÊÇÈç¹ûÕâ¸öÊý¾ÝÁ¿ºÜ´óµÄ»°,»áÒ»ÏÂ×Ó¹ÒËÀ.ËùÒÔ¾ÍÏëµ½ÁË.Äܲ»ÄÜ,ÿ´ÎÎÒ´«Ò»µã,¸ô¼¸ÃëÔÙËÍÒ»µã.
ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄÀý×Ó
declare @i int
set @i=1
while @i<101
begin
insert into Cname ([name],csex,Number) ......