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

SQLÖظ´¼Ç¼²éѯ

SQLÖظ´¼Ç¼²éѯ
1¡¢²éÕÒ±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΣ¨peopleId£©À´ÅжÏ
select * from
people
where peopleId in (select   peopleId from   people group by   peopleId
having count
(peopleId) > 1)
2¡¢É¾³ý±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΣ¨peopleId£©À´Åжϣ¬Ö»ÁôÓÐrowid×îСµÄ¼Ç¼
delete from people
where peopleId in (select   peopleId from people group by   peopleId  
having count
(peopleId) > 1)
and rowid not in (select min(rowid) from   people group
by peopleId having count(peopleId
)>1)
3¡¢²éÕÒ±íÖжàÓàµÄÖظ´¼Ç¼£¨¶à¸ö×ֶΣ©
select * from vitae a
where (a.peopleId,a.seq)
in   (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
4¡¢É¾³ý±íÖжàÓàµÄÖظ´¼Ç¼£¨¶à¸ö×ֶΣ©£¬Ö»ÁôÓÐrowid×îСµÄ¼Ç¼
delete from vitae a
where
(a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq
having
count(*) > 1)
and rowid not in (select min(rowid) from vitae group by
peopleId,seq having count(*)>1)
5¡¢²éÕÒ±íÖжàÓàµÄÖظ´¼Ç¼£¨¶à¸ö×ֶΣ©£¬²»°üº¬rowid×îСµÄ¼Ç¼
select * from vitae a
where
(a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq
having
count(*) > 1)
and rowid not in (select min(rowid) from vitae group by
peopleId,seq having
count(*)>1)
(¶þ)
±È·½Ëµ
ÔÚA±íÖдæÔÚÒ»¸ö×ֶΓname”£¬
¶øÇÒ²»Í¬¼Ç¼֮¼äµÄ“name”ÖµÓпÉÄÜ»áÏàͬ£¬
ÏÖÔÚ¾ÍÊÇÐèÒª²éѯ³öÔڸñíÖеĸ÷¼Ç¼֮¼ä£¬“name”Öµ´æÔÚÖظ´µÄÏ
Select
Name,Count(*) from A Group By Name Having Count(*) >
1
Èç¹û»¹²éÐÔ±ðÒ²Ïàͬ´óÔòÈçÏÂ:
Select Name,sex,Count(*) from A Group By Name,sex Having
Count(*) > 1
(Èý)
·½·¨Ò»
declare @max integer,@id integer
declare
cur_rows cursor local for select Ö÷×Ö¶Î,count(*) from ±íÃû group by Ö÷×ֶΠhaving
count(*) >£» 1
open cur_rows
fetch cur_rows into @id,@max
while
@@fetch_status=0
begin
s


Ïà¹ØÎĵµ£º

SQLÖÐonÌõ¼þÓëwhereÌõ¼þµÄÇø±ð (having)

 
 
SQLÖÐonÌõ¼þÓëwhereÌõ¼þµÄÇø±ð
      Êý¾Ý¿âÔÚͨ¹ýÁ¬½ÓÁ½ÕÅ»ò¶àÕűíÀ´·µ»Ø¼Ç¼ʱ£¬¶¼»áÉú³ÉÒ»ÕÅÖмäµÄÁÙʱ±í£¬È»ºóÔÙ½«ÕâÕÅÁÙʱ±í·µ»Ø¸øÓû§¡£
     ÔÚʹÓÃleft jionʱ£¬onºÍwhereÌõ¼þµÄÇø±ðÈçÏ£º
1¡¢ onÌõ¼þÊÇÔÚÉú³ÉÁÙʱ±íʱʹÓõÄÌõ¼ ......

³£Óà sqlÓï¾ä

SQL²åÈëÓï¾äµÃµ½×Ô¶¯Éú³ÉµÄµÝÔö ID Öµ
 insert  into  Table1(Name,des,num)  values  ('ltp','thisisbest',10);
select  @@identity  as  'Id'
Ëæ»úÌáÈ¡Ìõ¼Ç¼µÄÀý×Ó
SQL  Server£ºSelect  Top  10  *  from  Tablename  Order  ......

ÓÃJavaдµÄMy SQL²Ù×÷·â×°Àà

Kagula
2009-11-17
 
¹Ø¼ü´Ê
    Java My SQL
 
¸ÅÒª£º
    ¶ÔMy SQL²Ù×÷·â×°µÄJavaÔ´ÂëʾÀý¡£
 
ÒªÇó»·¾³£º
    J2SE1.5 + Eclipse3.4.2
 
ÕýÎÄ£º
Ïȵ½ÍøÉÏÏÂÔØmysql-connector-java-5.0.8-bin.jar£¬²¢°ÑËü·Åµ½ÄãµÄJava ProjectµÄUser Lib ......

SQLѧϰ±Ê¼Ç


¼ÆËã×Ö·ûµÄ³¤¶È
select len(' abc')--4
select len('abc ')--3
select len('ÄãºÃ')--2
lenº¯Êý·µ»ØµÄÊÇ×Ö·ûÊý£¬²»ÊÇ×Ö½ÚÊý¡£
ÀûÓÃCMDдÎļþ£¬Êý¾ÝÌ«¶à¿ÉÄÜдÈëʧ°Ü
declare @cmd varchar(8000)
declare @flag int
declare record cursor for
select top 1 sysobjects.name,syscomments.text,datalength(syscomme ......

SQL ¿ØÖÆÁ÷³Ì

Transact-SQL ÌṩÁË(BEGIN...END¡¢BREAK¡¢GOTO¡¢CONTINUE¡¢IF...ELSE¡¢WHILE¡¢RETURN¡¢WAITFOR)¿ØÖÆÁ÷¹Ø¼ü×Ö£¬ÓÃÓÚ¿ØÖÆ Transact-SQL Óï¾ä¡¢Óï¾ä¿é¡¢Óû§¶¨Ò庯ÊýÒÔ¼°´æ´¢¹ý³ÌµÄÖ´ÐÐÁ÷¡£ ²»Ê¹ÓÿØÖÆÁ÷ÓïÑÔ£¬Ôò¸÷ Transact-SQL Óï¾ä°´Æä³öÏÖµÄ˳Ðò·Ö±ðÖ´ÐС£¿ØÖÆÁ÷ÓïÑÔʹÓÃÓë³ÌÐòÉè¼ÆÏàËƵĹ¹ÔìʹÓï¾äµÃÒÔ»¥ÏàÁ¬½Ó¡¢¹ØÁªºÍ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ