SQLɾ³ýÖ¸¶¨×Ö¶ÎÎÊÌâ
¸üÐÂÏÂÎÊÌ⣺
񡜧TBL_Info
×ֶΣº
infoId int
title varchar(20)
Content text
byUser varchar(20)
createTime datetime
1¡¢ÈçºÎɾ³ý±íÖÐÊý¾ÝÏàͬµÄÊý¾ÝÄØ£¿£¨Ö÷¼ü³ýÍ⣩
2¡¢ÈçºÎɾ³ýÊý¾Ý±íÖÐij¸ö×Ö¶ÎÊý¾ÝÏàͬµÄÊý¾ÝÄØ(±ÈÈçtitle£ºÉ¾³ýËùÓÐtitleÏàͬµÄÊý¾Ý)£¿
3¡¢ÈçºÎͳ¼Æ±íÖÐtitleÏàͬÊý¾ÝµÄÊýÄ¿£¿
--1
--1.1Ïàͬʱ±£Áô×îСµÄinfoId
delete TBL_Info from TBL_Info t where infoId not in (select min(id) from infoId where title = t.title and Content = t.Content and byUser = t.byUser and createTime = t.createTime)
--1.1Ïàͬʱ±£Áô×î´óµÄinfoId
delete TBL_Info from TBL_Info t where infoId not in (select max(id) from infoId where title = t.title and Content = t.Content and byUser = t.byUser and createTime = t.createTime)
--2
delete from TBL_Info where title in (select title from TBL_Info group by title having count(1) > 1)
--3
select title , count(1) from TBL_Info group by title
select title , count(*) from TBL_Info group by title
select title , count(title) from TBL_Info group by title
--¹¦ÄܸÅÊö:ɾ³ýÖظ´¼Ç¼
ÔÚ¼¸Ç§Ìõ¼Ç¼Àï,´æÔÚ×ÅЩÏàͬµÄ¼Ç¼,ÈçºÎÄÜÓÃ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¡¢É¾³ý±íÖж
Ïà¹ØÎĵµ£º
ºÜ¶àʱºò£¬ÎÒÃÇ¿ÉÄÜÏ£Íû°´Ô¡¢°´Ìì¡¢°´Äê×öһЩÊý¾Ýͳ¼Æ£¬µ«ÊÇ£¬ÎÒÃÇʵ¼Ê±£´æµÄÊý¾Ý¿ÉÄÜÊÇÒ»¸öºÜ¾«È·µÄ·¢Éúʱ¼ä£¬¿ÉÄÜÊǵ½Ãë¡£ÈçºÎ¸ù¾ÝÒ»¸öʱ¼äÖ®½ØÈ¡ÆäÖеÄÒ»²¿·Ö¾Í³ÉÁËÎÊÌâ¡£
ÓÐÁ½¸ö½â¾ö·½·¨£º
×îÖ±½ÓµÄÏë·¨ÀûÓÃDatePart»òÕßYear¡¢Month¡¢Dayº¯Êý
CAST(
(
STR( Y ......
º¯ÊýÊÇÒ»ÖÖÓÐÁã¸ö»ò¶à¸ö²ÎÊý²¢ÇÒÓÐÒ»¸ö·µ»ØÖµµÄ³ÌÐò¡£ÔÚSQLÖÐOracleÄÚ½¨ÁËһϵÁк¯Êý£¬ÕâЩº¯Êý¶¼¿É±»³ÆΪSQL»òPL/SQLÓï¾ä£¬º¯ÊýÖ÷Òª·ÖΪÁ½´óÀࣺ
µ¥Ðк¯Êý¡¢×麯Êý
±¾ÎĽ«ÌÖÂÛÈçºÎÀûÓõ¥Ðк¯ÊýÒÔ¼°Ê¹ÓùæÔò¡£
SQLÖеĵ¥Ðк¯Êý
SQLºÍPL/SQLÖÐ×Ô´øºÜ¶àÀàÐ͵ĺ¯Êý£¬ÓÐ×Ö·û¡¢Êý×Ö¡¢ÈÕÆÚ¡¢×ª»»¡¢ºÍ»ìºÏÐ͵ȶàÖÖº¯ ......
¡¡¡¡Ò»¡¢ ¼òµ¥²éѯ
¡¡¡¡¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
¡¡¡¡ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
¡¡¡¡SELECT nickname,email
¡¡¡¡from testtable
¡¡¡¡WHERE name=' ......
ËùνÌìÏ´óÊ£¬·Ö¾Ã±ØºÏ£¬ºÏ¾Ã±Ø·Ö£¬¶ÔÓÚ·ÖÇø±í¶øÑÔÒ²Ò»Ñù¡£Ç°ÃæÎÒÃǽéÉܹýÈçºÎɾ³ý£¨ºÏ²¢£©·ÖÇø±íÖеÄÒ»¸ö·ÖÇø£¬ÏÂÃæÎÒÃǽéÉÜÒ»ÏÂÈçºÎΪ·ÖÇø±íÌí¼ÓÒ»¸ö·ÖÇø¡£
Ϊ·ÖÇø±íÌí¼ÓÒ»¸ö·ÖÇø£¬ÕâÖÖÇé¿öÊÇʱ³£»á
·¢ÉúµÄ¡£±ÈÈ磬×î³õÔÚÊý¾Ý¿âÉè¼Æʱ£¬Ö»Ô¤¼ÆÁË´æ·Å3ÄêµÄÊý¾Ý£¬¿ÉÊǵ½Á˵Ú4ÌìÔõ ......
µÚÒ»´Î°²×°2005,»¨Á˲»ÉÙ¾«Á¦¡£ËäȻûʲô̫Äѵģ¬µ«ÊDz»ÖªµÀµÄ»°»áºÜ¼¬Êֵġ£Èç¹ûÄãÕýÔÚ°²×°£¬²¢ÇÒ·¢ÏÖÕâƪÎÄÕ£¬ÄÇôÄãºÜ×ßÔË£¬Ä㽫»á˳ÀûµÄ°²×°³É¹¦¡£
°²×°Ä¿Â¼Öаüº¬Sql Server x64 ºÍ x86, x86ÊÇ32λ»úÆ÷µÄ¡£x86ÖÐÓÖÓÐtools ºÍ Servers ¡£µÚÒ»´Î°²×°ÁËServers£¬È» ......