Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÇóÕâ¾äSqlÈçºÎÀí½â

create table [¿Í»§ÁªÏµ±í]([¿Í»§±àºÅ] varchar(2),[ÁªÏµÈÕÆÚ] datetime,[ÁªÏµÄÚÈÝ] int)
insert [¿Í»§ÁªÏµ±í]
select 'aa','2009/01/01',111 union all
select 'bb','2009/02/01',222 union all
select 'aa','2009/03/01',333 union all
select 'aa','2009/04/01',444 union all
select 'bb','2009/05/01',555

select b.¿Í»§±àºÅ, b.ÁªÏµÈÕÆÚ,b.ÁªÏµÄÚÈÝ from ¿Í»§ÁªÏµ±í b where not exists(select 1 from ¿Í»§ÁªÏµ±í where ¿Í»§±àºÅ=b.¿Í»§±àºÅ and ÁªÏµÈÕÆÚ >b.ÁªÏµÈÕÆÚ)


½á¹ûΪ£ºaa  2009-04-01 00:00:00.000 444
        bb  2009-05-01 00:00:00.000 555

Çó£ºnot existsÕâ¾äÈçºÎÀí½â
²»Ã÷°×ΪɶÇó³öÀ´¾ÍÊÇ×îºóÈÕÆÚ
²»°üº¬£¡£¡

Ïàͬ¿Í»§±àºÅ£¬ÏÔʾ×î½üÁªÏµµÄ

´ó¸ç£¬ÄÃÕâ¸öÀý×Ó½²Ïêϸµã

not exists ÔÙ¼ÓÉÏÁªÏµÈÕÆÚ >b.ÁªÏµÈÕÆÚ£¬¾ÍÏñË«ÖØ·ñ¶¨µÄÒâ˼£¬×îºóµÃµ½bµÄ½á¹û¾ÍÊÇ×îеÄÁªÏµÈÕÆÚ

where not exists(select 1 from ¿Í»§ÁªÏµ±í where ¿Í»§±àºÅ=b.¿Í»§±àºÅ and ÁªÏµÈÕÆÚ >b.ÁªÏµÈÕÆÚ)

Ï൱ÓÚ

where ÁªÏµÈÕÆÚ  not in(select top 1 ÁªÏµÈÕÆÚ from ¿Í»§ÁªÏµ±í where ¿Í»§±àºÅ=b.¿Í»§±àºÅ and ÁªÏµÈÕÆÚ >b.ÁªÏµÈÕÆÚ)

select b.¿Í»§±àºÅ, b.ÁªÏµÈÕÆÚ,b.ÁªÏµÄÚÈÝ from ¿Í»§ÁªÏµ±í b where not exists(select 1 from ¿Í»§ÁªÏµ±í where ¿Í»§±àºÅ=b.¿Í»§±àºÅ and ÁªÏµÈÕÆÚ >b.ÁªÏµÈÕÆÚ)

¿Í»§±àºÅ=b.¿Í»§±àºÅ  ½á¹ûΪaaºÍbb
ÁªÏµÈÕ


Ïà¹ØÎÊ´ð£º

sql ʱ¼äÎÊÌâ

sql table±íÓиöÎı¾ÀàÐ͵Äa×ֶΣ¬´æ´¢µÄÄÚÈÝÈ«²¿ÊÇÊý×Ö£¬ÀýÈç2009001£¬2008578ÕâÑùµÄ¸ñʽ£»b×Ö¶ÎÎı¾ÀàÐÍ£¬´æµÄÒ²ÊÇÊý×ÖÀýÈç 001£¬123
aspÀïÃæ strday=100£¬strb=001

ÎÒÏë¶Á³ö£¬´Óa×ֶεÄÊý×Ö°´´óµ½Ð¡µÄË ......

SQLÓï¾äÕýÈ·µ«ÊÇRESULTSETÖÐûÓÐÖµ

StringBuffer str = new StringBuffer("select * from menu where parentid=1 and mid <>1 order by parentid");

List list = new ArrayList();
ResultSet rst = null;
DataBa ......

Çë½ÌÒ»¸öSQLÓ¦ÓÃÎÊÌâ

ÓÐʱºòÔÚÊý¾ÝÖвéѯÊý¾ÝµÄʱºò¿¼ÂÇÐÔÄÜÎÊÌ⣬»á½«¸´ÔÓÓï¾ä²ð·Ö»ò½èÓÃÁÙʱ±íÀ´¶à´Î²éѯ×îÖյõ½ÏëÒªµÄÊý¾Ý£¬ÏÖÔÚ½«ÕâЩ²éѯÄÚÈÝ×ö³É±¨±í£¬ÐèҪд¸öÓï¾äÒ»ÆøºÇ³É¡£
ÎÒÏëÎʵÄSQLÊÇ·ñ¿ÉÒÔÔÚ²éѯÓï¾äÒ»½áÊøºó£¬ÔÙ×Ô¶¯Ô ......

Çó×ésqlÓï¾ä(a+b)=a

ÇóÔÚһͬһ¸ö±íÀïÃæ
a  b
10  7
(a-b)=a
ÔÚÔ­À´µÄ±íA¶Î¸üÐÂΪ3
ÏÈлл¸÷λÁË,°ï¸öæ
SQL code:
update a set a=a-b


SQL code:
-->Title:Generating test data
-->Author ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ