sql ³£ÓòÙ×÷Óï¾äÊÕ¼¯
Ò»
SQLÖظ´¼Ç¼²éѯ£¨×ª×Ôhttp://blog.csdn.net/RainyLin/archive/2009/02/17/3901956.aspx£©
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(*) >£»
Ïà¹ØÎĵµ£º
Êý¾Ý¿âÊÂÎñÊÇÆäËûÊÂÎñÄ£Ð͵Ļù´¡£¬µ±Ò»¸öÊÂÎñ´´½¨Ê±²»Í¬Êý¾Ý¿âϵͳ¶¼ÓÐ×Ô¼ºµÄ¹æ
Ôò¡£SQL Server ĬÈÏÔÚ×Ô¶¯Ìá½»µÄģʽϹ¤×÷£¬Ã¿¸öÓï¾äÖ´ÐÐÍêºó¶¼»áÁ¢¼´Ìá½»£»Óë´Ë¶ÔÕÕ
µÄÊÇ Oracle ÐèÒªÄã°üº¬Ò»¸öÌá½»Óï¾ä¡£µ«Êǵ±Ò»¸öÓï¾äͨ¹ý OLE DB Ö´ÐÐʱ£¬ËüÖ´ÐÐÍêºó
Ò»¸öÌá½»¶¯×÷»á±»¸½¼ÓÉÏÈ¥¡£ÀýÈ磺
DECLARE  ......
--Óï ¾ä ¹¦ ÄÜ
1¡¢Êý¾Ý²Ù×÷
Select --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
Insert & ......
http://cheneyph.javaeye.com/blog/453492
ÓÃoracle sql¶ÔÊý×Ö½øÐвÙ×÷: È¡ÉÏÈ¡Õû¡¢ÏòÏÂÈ¡Õû¡¢±£ÁôNλСÊý¡¢ËÄÉáÎåÈë¡¢Êý×Ö¸ñʽ»¯
È¡Õû£¨ÏòÏÂÈ¡Õû£©£º
select floor(5.534) from dual;
select trunc(5.534) from dual;
ÉÏÃæÁ½ÖÖÓ÷¨¶¼¿ÉÒÔ¶ÔÊý×Ö5.534ÏòÏÂÈ¡Õû£¬½á¹ûΪ5.
Èç¹ûÒªÏòÉÏÈ¡Õû £¬µÃµ½½á¹ûÎ ......
--SQL ½ØÈ¡×Ö·û´®·½·¨£¬ÖÐÎÄËãÁ½¸ö×Ö·ûµÄ·½·¨¡£
--·½·¨¸úË®¸çѧϰµÄ£¬Ö§³ÖÒ»ÏÂË®¸çµÄ²©¿Í
--http://hi.csdn.net/link.php?url=http://blog.csdn.net%2Fwufeng4552
--Ë®¸ç×î½üлÁ˺ö಩¿Í£¬ÓÐʱ¼äÒ»¶¨È¥ºÃºÃѧϰ
--LEFT() ºÍSUBSTRING()¶¼Êǽ«ºº×ÖËãÒ»¸ö×Ö·ûÀ´ËãµÄ
--Èç¹û²»¼Æ½ÏµÄ»°£¬ÍƼöʹÓÃÕâÁ½¸öϵͳº¯Êý
IF OBJE ......
Ò»¡¢×Ö·ûת»»º¯Êý
1¡¢ASCII()
·µ»Ø×Ö·û±í´ïʽ×î×ó¶Ë×Ö·ûµÄASCII ÂëÖµ¡£ÔÚASCII£¨£©º¯ÊýÖУ¬´¿Êý×ÖµÄ×Ö·û´®¿É²»ÓÑ’À¨ÆðÀ´£¬µ«º¬ÆäËü×Ö·ûµÄ×Ö·û´®±ØÐëÓÑ’À¨ÆðÀ´Ê¹Ó㬷ñÔò»á³ö´í¡£
2¡¢CHAR()
½«ASCII Âëת»»Îª×Ö·û¡£Èç¹ûûÓÐÊäÈë0 ~ 255 Ö®¼äµÄASCII ÂëÖµ£¬CHAR£¨£© ·µ»ØNULL ¡£
3¡¢LOWER()ºÍ ......