sql code
Õâsql Óï¾äдµÄÕæµÄºÜ²»´í!
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col1] bigint,[col2] varchar(6),[col3] varchar(6))
insert [tb]
select 130126200201000275,'ÍõÎÄϼ','½ù´¨´¨' union all
select 130126200201000275,'ÍõÎÄϼ','½ù澤' union all
select 130126200201000275,'ÍõÎÄϼ','aaaa' union all
select 130126200201000276,'ÖÜ書¶ð','³Ì˼³¬' union all
select 130126200201000276,'ÖÜ書¶ð','³Ìٮٮ' union all
select 130126200201000277,'風¾Õ','³ÌÇàÇà' union all
select 130126200201000277,'風¾Õ','³Ì¶þС' union all
select 130126200201000278,'張Ó¢ÌÒ','³Ì´ó慶' union all
select 130126200201000278,'張Ó¢ÌÒ','³ÌС»¨'
--------------¿ªÊ¼²éѯ--------------------------
select * from tb
select col2,col3 from
(
select col1,col2,col3 from [tb] t
where not exists(select * from tb where col1=t.col1 and col2=t.col2 and col3>t.col3)
union all
select col1,'',col3 from [tb] t
where exists(select 1 from tb where col1=t.col1 and col2=t.col2 and col3>t.col3)
)T
order by col1,col3 desc
Ïà¹ØÎĵµ£º
Èç¹ûÄãÕýÔÚ¸ºÔðÒ»¸ö»ùÓÚSQL ServerµÄÏîÄ¿£¬»òÕßÄã¸Õ¸Õ½Ó´¥SQL Server£¬Äã¶¼ÓпÉÄÜÒªÃæÁÙһЩÊý¾Ý¿âÐÔÄܵÄÎÊÌ⣬ÕâÆªÎÄÕ»áΪÄãÌṩһЩÓÐÓõÄÖ¸µ¼£¨ÆäÖдó¶àÊýÒ²¿ÉÒÔÓÃÓÚÆäËüµÄDBMS£©¡£
ÔÚÕâÀÎÒ²»´òËã½éÉÜʹÓÃSQL ServerµÄÇÏÃÅ£¬Ò²²»ÄÜÌṩһ¸ö°üÖΰٲ¡µÄ·½°¸£¬ÎÒËù×öµÄÊÇ×ܽáһЩ¾Ñé----¹ØÓÚÈçºÎÐγÉÒ»¸öºÃµÄÉè¼Æ¡£Õ ......
1. Nested Loop Join(ǶÌ×Ñ»·Áª½á)
Ëã·¨£º
Æä˼·Ï൱µÄ¼òµ¥ºÍÖ±½Ó£º¶ÔÓÚ¹ØÏµRµÄÿ¸öÔª×é r ½«ÆäÓë¹ØÏµSµÄÿ¸öÔª×é s ÔÚJOINÌõ¼þµÄ×Ö¶ÎÉÏÖ±½Ó±È½Ï²¢É¸Ñ¡³ö·ûºÏÌõ¼þµÄÔª×顣д³Éα´úÂë¾ÍÊÇ£º
´ú¼Û£º
±»Áª½áµÄ±íËù´¦ÄÚ²ã»òÍâ²ãµÄ˳Ðò¶Ô´ÅÅÌI/O¿ªÏúÓÐ×ŷdz£ÖØÒªµÄÓ°Ïì¡£¶øCPU¿ªÏúÏà¶ÔÀ´ËµÓ°Ïì½ÏС£¬Ö÷ÒªÊÇÔª×é¶ÁÈ ......
Create PROCEDURE UpdateWanjun
@UserName nvarchar(500),
@UserPassword nvarchar(500),
@ReturnVal int output
AS
--Set XAcT_ABORT ON
Begin Transaction T
Update admins set UserPassword = @UserPassword wh ......
--ÐÐÁÐת»» ÐÐתÁÐ
DROP TABLE t_change_lc;
CREATE TABLE t_change_lc (card_code VARCHAR2(3), q NUMBER, bal NUMBER);
INSERT INTO t_change_lc
SELECT '001' card_code, ROWNUM q, trunc(dbms_random.VALUE * 100) bal from dual CONNECT BY ROWNUM <= 4
UNION
SELECT '002' card_code, ROWNUM q, trunc(d ......