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

Çó½ÌÒ»¸öSQL²éѯ£¬²éѯһ¸ö±íÀïÿ¸ö²»Í¬µØÇøµÄ×î´óÊý

ÒªÇóÈçÏ£º
    Ò»¸ö±í£¬½á¹¹ÈçÏ£º
ID£¬±àºÅÊý£¬µØÇø
1£¬ 090001£¬¹ãÖÝ
2£¬ 090002£¬Ïã¸Û
3£¬ 090003£¬¹ãÖÝ
4£¬ 090004£¬¶«¾©
5£¬ 090005£¬¹ãÖÝ
6£¬ 090006£¬Ïã¸Û
7£¬ 090007£¬¹ãÖÝ
8£¬ 090008£¬Ïã¸Û

ÒªÇó»ñµÃÿ¸öµØÇøµÄ×î´ó±àºÅÊý
¼´»ñµÃ½á¹ûΪ£º¹ãÖÝ£¬090007
              Ïã¸Û£¬090008
              ¶«¾©£¬090004

ÕâÑùÒ»¸öSQL²éѯÈçºÎд£¿

select µØÇø£¬max(±àºÅÊý) from ±í group by µØÇø

SQL code:
select µØÇø,max(±àºÅÊý) from tb
group by µØÇø


SQL code:
--or
select * from tb t where not exists(select 1 from tb where µØÇø=t.µØÇø and ±àºÅÊý>t.±àºÅÊý )


SQL code:
-->Title:Generating test data
-->Author:wufeng4552
-->Date :2009-10-07 14:47:36

if not object_id('tb') is null
drop table tb
Go
Create table tb([ID] int,[±àºÅÊý] nvarchar(6),[µØÇø] nvarchar(2))
Insert tb
select 1,N'090001',N'¹ãÖÝ' union all
select 2,N'090002',N'Ïã¸Û' union all
select 3,N'090003',N'¹ãÖÝ' union all
select 4,N'090004',


Ïà¹ØÎÊ´ð£º

ÇóSQL£¿

´ó¼ÒºÃ£¬ÇëÎÊÔÚ±íMÖÐÓÐ×ֶΣºa b c d e 
ÎÒÏë²é³öÆäÖÐÂú×ãÏÂÃæÈÎÒâÒ»ÏîµÄÊý¾Ý£¬1.×Ö¶Îa µÄÖµ²»ÊÇ ¡®Êé»ò±Ê»ò±¾¡¯ÖÐÈÎÒ»£¬2.aΪÊéµÄʱºò×Ö¶Îb,cÊÇ¿Õ;3.µ±aֵΪ±ÊµÄʱºòdÊÇ¿Õ;4.µ±aΪ±¾µÄʱºòb,d,e¶¼ÊÇ¿Õ;5.È ......

¹ØÓÚgroup byµÄsqlÓï¾ä£¿

  with adod_dict do
    begin
    close;
    commandtext:='select bgqxcode,count(*) wjsl from wscl_wsda_file where wjnd=:tnd group by bgqxcode'; ......

SQLÓï¾äÎÊÌ⣬¸ßÊÖ°ïæ£¡£¡

½«Ò»¸ö±í21~30ɾ³ý£¬sqlÓï¾äÔõôд
Õâ¸öÌ«ÁýͳÁË£¬ÊÇÅÅÐòºóµÄµÚ21Ìõµ½30Ìõ¼Ç¼ɾ³ý»¹ÊÇijһÁÐÖµÔÚ21µ½30Ö®¼äµÄɾ³ý°¡£¿

21-30ÊÇʲôÒâ˼£¿×ֶεϰ¾Ídelete from table1 where col1>=21 and col1<=30
Ö¸µ ......

SQLÓï¾äЧÂÊÎÊÌâ - ÆäËûÊý¾Ý¿â¿ª·¢ / ÆäËûÊý¾Ý¿â

´ó¼Ò°ïæ¿´¿´Õâ2¸ösqlÓï¾äÄĸö²éѯµÄËٶȸü¿ìµã¡£Ð»Ð»°ïæ¡£±È½Ï׿±¡£ÔÚ×öÐÔÄܲâÊÔ¡£
select * from
  ±íA LEFT OUTER JOIN ±íB ON (±íA.id || ' ' =±íB.id) ,±íC , ±íD, ±íE
WhereÆäËûÌõ¼þ
select * ......

²»Ã÷°×µÄSQL×¢ÈëÎÊÌâ

ÎÒÊý¾Ý¿âÊÇMSSQLµÄ£¬×òÌìËùÓÐµÄ±í±»×¢ÈëJS½Å±¾´úÂë,Óиö²»Ã÷°×µÄµØ·½À´ÎÊÎÊ´ó¼Ò

ÎÒ·¢ÏÖÓÐЩ±íÎÒ¸ù±¾Ã»Ê¹Óã¬Ò²Ã»ÓÐÈë¿âµÄASPÒ³ÃæºÍÓï¾ä£¬ËüÊÇÔÛ¸ö×¢ÈëµÄÄØ£¿
Ã²ËÆselectÓï¾äÊÇ¿ÉÒÔǶÌ׵İɣ¿
¿ÉÄÜÊÇwhere ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ