SQL²éѯЧÂÊ 100wÊý¾Ý²éѯֻҪ1Ãë
»úÆ÷Çé¿ö
p4: 2.4
ÄÚ´æ: 1 G
os: windows 2003
Êý¾Ý¿â: ms sql server 2000
Ä¿µÄ: ²éѯÐÔÄܲâÊÔ,±È½ÏÁ½ÖÖ²éѯµÄÐÔÄÜ
SQL²éѯЧÂÊ step by step
-- setp 1.
-- ½¨±í
create table t_userinfo
(
userid int identity(1,1) primary key nonclustered,
nick varchar(50) not null default '',
classid int not null default 0,
writetime datetime not null default getdate()
)
go
-- ½¨Ë÷Òý
create clustered index ix_userinfo_classid on t_userinfo(classid)
go
-- step 2.
declare @i int
declare @k int
declare @nick varchar(10)
set @i = 1
while @i<1000000
begin
set @k = @i % 10
set @nick = convert(varchar,@i)
insert into t_userinfo(nick,classid,writetime) values(@nick,@k,getdate())
set @i = @i + 1
end
-- ºÄʱ 08:27 £¬ÐèÒªÄÍÐĵȴý
-- step 3.
select top 20 userid,nick,classid,writetime from t_userinfo
where userid not in
(
select top 900000 userid from t_userinfo order by userid asc
)
-- ºÄʱ 8 Ãë ,¹»³¤µÄ
-- step 4.
select a.userid,b.nick,b.classid,b.writetime from
(
select top 20 a.userid from
(
select top 900020 userid from t_userinfo order by userid asc
) a order by a.userid desc
) a inner join t_userinfo b on a.userid = b.userid
order by a.userid asc
-- ºÄʱ 1 Ã룬̫¿ìÁË°É£¬²»¿ÉÒÔ˼Òé
-- step 5 where ²éѯ
select top 20 userid,nick,classid,writetime from t_userinfo
where classid = 1 and userid not in
(
select top 90000 userid from t_userinfo
where classid = 1
order by userid asc
)
-- ºÄʱ 2 Ãë
-- step 6 where ²éѯ
select a.userid,b.nick,b.classid,b.writetime from
(
select top 20 a.userid from
(
select top 90000 userid from t_userinfo
where classid = 1
order by userid asc
) a order by a.userid desc
) a inner join t_userinfo b on a.userid = b.userid
order by a.userid asc
-- ²éѯ·ÖÎöÆ÷ÏÔʾ²»µ½ 1 Ãë.
²éѯЧÂÊ·ÖÎö£º
×Ó²éѯΪȷ±£Ïû³ýÖظ´Öµ£¬±ØÐëΪÍⲿ²éѯµÄÿ¸ö½á¹û¶¼´¦ÀíǶÌײéѯ¡£ÔÚÕâÖÖÇé¿öÏ¿ÉÒÔ¿¼ÂÇÓÃÁª½Ó²éѯÀ´È¡´ú¡£
Èç¹ûÒªÓÃ×Ó²éѯ£¬ÄǾÍÓÃEXISTSÌæ´úIN¡¢ÓÃNOT EXISTSÌæ´úNOT IN¡£ÒòΪEXISTSÒýÈëµÄ×Ó²éѯֻÊDzâÊÔÊÇ·ñ´æÔÚ·ûºÏ×Ó²éѯ
Ïà¹ØÎĵµ£º
SELECT DISTINCT '['+user_name(b.uid)+'].['+b.name+']' AS ¶ÔÏóÃû,b.type AS ÀàÐÍ
from sysdepends a,sysobjects b
WHERE b.id=a.depid
AND a.id=OBJECT_ID('¹ý³ÌÃû');
EXEC SP_DEPENDS '¹ý³ÌÃû';
......
Êý¾Ý²Ù×÷Àà SQLHelper.cs
http://www.cnblogs.com/zengxiangzhan/archive/2009/12/31/1636871.html
ÎÞÏÞ¼¶·ÖÀà ´æ´¢¹ý³Ì
http://www.cnblogs.com/zengxiangzhan/archive/2010/01/04/1639220.html
°ÙÍò¼¶·ÖÒ³´æ´¢
http://www.cnblogs.com/zengxiangzhan/archive/2009/09/12/1565313.html
SQL¾µä¶ÌС´úÂëÊÕ¼¯
htt ......
ÎÒÃÇÒª×öµ½²»µ«»áдSQL,»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQL,ÒÔÏÂΪ±ÊÕßѧϰ¡¢ÕªÂ¼¡¢²¢»ã×ܲ¿·Ö×ÊÁÏÓë´ó¼Ò·ÖÏí£¡
£¨1£© Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLE µÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦À ......
Insert Into Êý¾Ý±íÃû³Æ(×Ö¶ÎÃû³Æ1,×Ö¶ÎÃû³Æ2,...) values(×Ö¶ÎÖµ1,×Ö¶ÎÖµ2,...)
insert into user(username,password,age) values('ÀîÀÏËÄ','6666',45)
Update Êý¾Ý±íÃû³Æ Set ×Ö¶ÎÃû³Æ=×Ö¶ÎÖµ,×Ö¶ÎÃû³Æ=×Ö¶ÎÖµ,...[Where Ìõ¼þ]
Delete from Êý¾Ý±í
ÏÂÁвéѯ·µ»ØÔÚLONDON£¨Â׶أ©»òSEATTLE£¨Î÷ÑÅͼ£©µÄËùÓйÍÔ±£º
S ......
--¾ÛºÏº¯Êý
use pubs
go
select avg(distinct price) --Ëãƽ¾ùÊý
from titles
where type='business'
go
use pubs
go
select max(ytd_sales) --×î´óÊý
from titles
go
use pubs
go
select min(ytd_sales)& ......