count(*) ±Ècount(id)ºÃ
select count(DISTINCT t_enter,caller) as size from tab¿ÉÒÔÌß³öÖØ¸´Í³¼Æ
mysql¿ÉÒÔ¶ÏÕÂÈ¡Ò壨´Ó0¿ªÊ¼10¸ö£©
select * as size from tab limit 0,10
Ò²¿ÉÒÔȡǰ¼¸¸ö
select * as size from tab limit 10
¾ÍµÈ¼ÛÓëmssqlµÄtop
select top 10 * as size from tab
mssqlserverҪʵÏÖlimitµÄѡȡ¹¦ÄܾͱȽÏÂé·³±ÈÈç´Ó4¡«6¿ÉÒÔÈçÏÂд·¨£º
select * from (select top 3 * from (select top 6 * from @t order by id)a order by a.id desc)b order by b.id
===============================================ÒÔÏÂÊdzÀ´µÄ
http://www.west263.com/www/info/34371-1.htm
create table [testtable] (
[id] [int] identity (1, 1) not null ,
[firstname] [nvarchar] (100) collate chinese_prc_ci_as null ,
[lastname] [nvarchar] (100) collate chinese_prc_ci_as null ,
[country] [nvarchar] (50) collate chinese_prc_ci_as null ,
[note] [nvarchar] (2000) collate chinese_prc_ci_as null
) on [primary]
go
²åÈëÊý¾Ý£º(2ÍòÌõ£¬Óøü¶àµÄÊý¾Ý²âÊÔ»áÃ÷ÏÔһЩ)
set identity_insert testtable on
declare @i int
set @i=1
while @i<=20000
begin
insert into testtable([id], firstname, lastname, country,note) values(@i, firstname_xxx,lastname_xxx,country_xxx,note_xxx)
set @i=@i+1
end
set identity_insert testtable off
-------------------------------------
·ÖÒ³·½°¸Ò»£º(ÀûÓÃnot inºÍselect top·ÖÒ³)
Óï¾äÐÎʽ£º
select top 10 *
from testtable
where (id not in
(select top 20 id
from testtable
order by id))
order by id
select top Ò³´óС *
from testtable
where (id not in
(select top Ò³´óС*Ò³Êý id
from ±í
order by id))
order by id
-------------------------------------
·ÖÒ³·½°¸¶þ£º(ÀûÓÃid´óÓÚ¶àÉÙºÍselect top·ÖÒ³£©
Óï¾äÐÎʽ£º
select top 10 *
from testtable
where (id >
(select max(id)
from (select top 20 id
from testtable
order by id) as t))
order by id
select top Ò³´óС *
from testtable
where (id >
(select max(id)
from (select top Ò³´óС*Ò³Êý id
from ±í
order by id) as t))
order by id
-------------------------------------
·ÖÒ³·½°¸Èý£º(ÀûÓÃsqlµÄÓÎ±ê´æ´¢¹ý³Ì·ÖÒ³)
create procedure xiaozhengge
@sqlstr nvarchar(4000), --²éѯ×Ö·û´®
@currentpage int, --µÚnÒ³
@pagesize int --ÿҳÐÐÊý
as
set nocount on
declare @p1 int, --p1ÊÇÓαêµÄid
@rowcount int
exec sp_cursoropen @p1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as ×ÜÒ³Êý--,@rowcount as ×ÜÐÐÊý,@currentpage as µ±Ç°Ò³
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @p1,16,@currentpage,@pagesize
exec sp_cursorclose @p1
set nocount off
ÆäËüµÄ·½°¸£ºÈç¹ûûÓÐÖ÷¼ü£¬¿ÉÒÔÓÃÁÙʱ±í£¬Ò²¿ÉÒÔÓ÷½°¸Èý×ö£¬µ«ÊÇЧÂÊ»áµÍ¡£
½¨ÒéÓÅ»¯µÄʱºò£¬¼ÓÉÏÖ÷¼üºÍË÷Òý£¬²éѯЧÂÊ»áÌá¸ß¡£
ͨ¹ýsql ²éѯ·ÖÎöÆ÷£¬ÏÔʾ±È½Ï£ºÎҵĽáÂÛÊÇ:
·ÖÒ³·½°¸¶þ£º(ÀûÓÃid´óÓÚ¶àÉÙºÍselect top·ÖÒ³£©Ð§ÂÊ×î¸ß£¬ÐèҪƴ½ÓsqlÓï¾ä
·ÖÒ³·½°¸Ò»£º(ÀûÓÃnot inºÍselect top·ÖÒ³) ЧÂÊ´ÎÖ®£¬ÐèҪƴ½ÓsqlÓï¾ä
·ÖÒ³·½°¸Èý£º(ÀûÓÃsqlµÄÓÎ±ê´æ´¢¹ý³Ì·ÖÒ³) ЧÂÊ×î²î£¬µ«ÊÇ×îΪͨÓÃ
ÔÚʵ¼ÊÇé¿öÖУ¬Òª¾ßÌå·ÖÎö¡£