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_s
Ïà¹ØÎĵµ£º
±¾½ÚÖ÷Òª½éÉÜʹÓÃCLR´´½¨±êÁ¿º¯Êý£¬±íÖµº¯ÊýºÍ¾ÛºÏº¯Êý¡£
Ëùν±êÁ¿º¯ÊýÖ¸µÄ¾ÍÊǴ˺¯ÊýÖ»·µ»ØÒ»¸öÖµ¡£±íÖµº¯Êý·µ»ØÖµÊÇÒ»¸ö±í¡£¾ÛºÏº¯ÊýÊÇÔÚselectÓï¾äÖÐʹÓõģ¬ÓÃÀ´¾ÛºÏÒ»¸ö½á¹û¼¯£¬ÀàËÆÓÚSum()»òÊÇCount()µÈÄÚÖõĺ¯Êý£¬¶øÇÒÕæÕýµÄ×Ô¶¨Òå¾ÛºÏº¯ÊýÄ¿Ç°Ö»ÄÜÓÃCLRÀ´ÊµÏÖ¡£
ÏÂÃæµÄÀý×ÓʹÓÃÁËSQLServer×Ô´øµÄpubsÊý¾Ý¿â¡£
1 ......
int object_id('objectname');
´Ë·½·¨·µ»ØÊý¾Ý¿â¶ÔÏó±êʶºÅ¡£
ÆäÖУ¬²ÎÊýobjectname ±íʾҪʹÓõĶÔÏó£¬ÆäÊý¾ÝÀàÐÍΪnchar»òchar£¨Èç¹ûΪchar£¬ÏµÍ³½«Æäת»»Îªnchar£©
·µ»ØÀàÐÍΪint£¬±íʾ¸Ã¶ÔÏóÔÚϵͳÖеıàºÅ¡£
±ÈÈ磺
use wf_timesheet
select object_id('usp_check_excess_hours')
·µ»ØΪ197575742¡£
´Ë· ......
ÆäʵÔÚÐÞ¸ÄÊý¾Ý¿âÃû³Æ֮ǰ£¬Èç¹ûÓÐÓû§Á¬½Óµ½Êý¾Ý¿âµÄ»°»áÔì³ÉÊý¾Ý¿âÖØÃüÃûʧ°Ü£¬¿ÉÒÔÏÈÖ´ÐÐ
select spid
from master.dbo.sysprocesses
where dbid=db_id('OldDbName')
½á¹û¼¯ÖÐÏÔʾµÄÊǵ±Ç°Á¬½Óµ½Êý¾Ý¿âOldDbNameµÄÁ¬½Ó
±ÈÈç½á¹ûÊÇ
79
81
µ±È»£¬Êµ¼ÊÖµÓ¦¸Ã²»ÊÇÕâÁ½¸ö
È»ºóÖ´ÐÐ
kill 79
kill 81
¹Ø±ÕÒѽ¨Á¢ ......
ÔÚÎÒÃǵÄÈÕ³£±à³ÌÖУ¬Êý¾Ý¿âµÄ³ÌÐò»ù±¾É϶¼ÒªÓëSQLÓï¾ä´ò½»µÀ£¬SQLÓï¾äµÄ±àд²»¿É±ÜÃâµÄ³ÉΪһ¸öÍ·Ì۵Ť×÷¡£ÇÒÒòΪSQLÓï¾äÊÇSTRINGÀàÐÍ£¬Òò´ËÔÚ±àÒë½×¶Î²é²»³ö´í£¬Ö»Óе½ÔËÐÐʱ²ÅÄÜ·¢ÏÖ´íÎó¡£
±¾ÎĵĽâ¾ö·½°¸£¬Í¨¹ý×Ô¶¯Éú³ÉSQLÓï¾ä£¬ÔÚÒ»¶¨³Ì¶ÈÉϽµµÍ³ö´íµÄ¸ÅÂÊ£¬´Ó¶øÌá¸ß±à³ÌЧÂÊ¡£ public int ......
¡¾ÏÈ˼¿¼Ò»¸öÎÊÌ⣺Áû×ÓºÍϹ×ÓÔÚÒ»Æð»áÓÐʲô½á¹û£¿¡¿
×òÌìд³ÌÐò£¬ÓиöСģ¿éÊÇͨ¹ý·ÖÎöÊýÊ®ÍòÌõ¼Ç¼£¬ÓëÒì¹¹µÄÊý¾Ý±í½øÐбȶԣ¬ÕÒ³ö·ûºÏÌõ¼þµÄÐÅÏ¢¡£
ÔÚµÚÒ»Ìõ²éѯÖУ¬ÐèÒª²éѯËùÓмǼµÄÒ»¸ö×ֶΣ¬²¢ÌáÈ¡¸Ã×Ö¶ÎÖеĵÚ5ÖÁµÚ10¸ö×Ö·û´®£¬ÒªÓëÒì¹¹Êý¾Ý±í±È½ÏµÄ¾ÍÊÇÕâ¸ö×Ö´®¡£ÔÚ×î³õµÄ°æ±¾ÖУ¬¶ÔÓÚÐÔÄܲ¢Ã»ÓÐ×ö¸ü¶àµÄ¿¼Â ......