SQL¾µä¶ÌС´úÂëÊÕ¼¯
--SQL Server£º
Select TOP N * from TABLE Order By NewID()
--Access£º
Select TOP N * from TABLE Order By Rnd(ID)
Rnd(ID) ÆäÖеÄIDÊÇ×Ô¶¯±àºÅ×ֶΣ¬¿ÉÒÔÀûÓÃÆäËûÈκÎÊýÖµÀ´Íê³É£¬±ÈÈçÓÃÐÕÃû×Ö¶Î(UserName)
Select TOP N * from TABLE Order BY Rnd(Len(UserName))
--MySql£º
Select * from TABLE Order By Rand() Limit 10
--¿ªÍ·µ½NÌõ¼Ç¼
Select Top N * from ±í
--Nµ½MÌõ¼Ç¼(ÒªÓÐÖ÷Ë÷ÒýID)
Select Top M-N * from ±íWhere ID in (Select Top M ID from ±í) Order by ID Desc
--Ñ¡Ôñ10´Óµ½15µÄ¼Ç¼
select top 5 * from (select top 15 * from table order by id asc) table_±ðÃûorder by id desc
--Nµ½½áβ¼Ç¼
Select Top N * from ±íOrder by ID Desc
--ÏÔʾ×îºó5Ìõ¼Ç¼,µ«ÊÇÏÔʾµÄ˳Ðò±ØÐëΪ5,6,7,8,9,10,¶ø²»ÊÇ10,9,8,7,6,5 ÈçϽâ¾ö·½·¨:
select top 5 from test where id in(select top 5 from test order by id desc) order by id asc
--ͨ¹ýÕâ¸öÎÊÌâÒ²ÄÜ×ܽá³ö4-10Ìõ,5-100ÌõÕâÖÖÏÞ¶¨Ò»¶¨·¶Î§ÄÚµÄsqlÓï¾äµÄд·¨:
select top <Ä©¶ËID-¶¥¶ËID+1> * from <±íÃû> where ID not in(select top <¶¥¶ËID-1>) ID from <±íÃû>)
--ÀýÈç:4-10Ìõ¾ÍÓ¦¸Ãд³É
select top 10-4+1 * from test where id not in(select top 4-1 id from test)
ÉÏһƪ: select top 1 * from [news_table] where [ÐÂÎűêʶÁÐ]<µ±Ç°idºÅ where ......
ÏÂһƪ: select top 1 * from [news_table] where [ÐÂÎűêʶÁÐ]>µ±Ç°idºÅ where ...... order by [ÐÂÎűêʶÁÐ] desc --Á½Ìõ¼Ç¼ÍêÈ«Ïàͬ£¬ÈçºÎɾ³ýÆäÖÐÒ»Ìõ
set rowcount=1
delete from thetablename where id=@duplicate_id--@duplicate_idΪÖظ´ÖµµÄid
--Ä£ºý²éѯ
select * &nbs
Ïà¹ØÎĵµ£º
1½«sqlÖÐʹÓõÄһЩÌØÊâ·ûºÅ£¬Èç' -- /* ; %µÈÓÃReplace()¹ýÂË£»
2ÏÞÖÆÎı¾¿òÊäÈë×Ö·ûµÄ³¤¶È£»
3¼ì²éÓû§ÊäÈëµÄºÏ·¨ÐÔ£»¿Í»§¶ËÓë·þÎñÆ÷¶Ë¶¼ÒªÖ´ÐУ¬¿ÉÒÔʹÓÃÕýÔò¡£
4ʹÓôø²ÎÊýµÄSQLÓï¾äÐÎʽ¡£
ASP.NETÖÐÈçºÎ·À·¶SQL×¢Èëʽ¹¥»÷
Ò»¡¢Ê²Ã´ÊÇSQL×¢Èëʽ¹¥»÷£¿
¡¡¡¡ËùνSQL×¢Èëʽ¹¥»÷£¬¾ÍÊǹ¥»÷Õß°Ñ ......
--¾ÛºÏº¯Êý
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)& ......
»úÆ÷Çé¿ö
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 nul ......
¹¤×÷ÖÐÅöµ½µÄС¼¼ÇÉ£¬±ÈÈç˵ҪÓÃÊý¾Ý±íÀïÈ¡³ö×¢²áÓû§µÄ×ÊÁÏ£¬ÐÔ±ðΪ1ÔòÏÔʾΪÄÐÉú£»ÐÔ±ðΪ2ÔòÏÔʾΪŮÉú£»ÒÔÇ°¶¼ÊÇ´Ó±íÀïÈ¡³öÊý¾Ý£¬È»ºóÔÙÓôúÂë½øÐÐÅжϣ¬Îª1ÔòÏÔʾΪÄÐÉú£»Îª2ÔòÏÔʾΪŮÉú£»Æäʵµ¥ÓÃSQLÓï¾ä¾Í¿ÉÒÔ×öµ½£¬ÈçÏ£º
Ö±½ÓʹÓÃcase when else Óï¾ä
Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseË ......