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

sql²éѯÓÅ»¯


1¡¢    ÓóÌÐòÖУ¬±£Ö¤ÔÚʵÏÖ¹¦ÄܵĻù´¡ÉÏ£¬¾¡Á¿¼õÉÙ¶ÔÊý¾Ý¿âµÄ·ÃÎÊ´ÎÊý£»Í¨¹ýËÑË÷²ÎÊý£¬¾¡Á¿¼õÉÙ¶Ô±íµÄ·ÃÎÊÐÐÊý,×îС»¯½á¹û¼¯£¬´Ó¶ø¼õÇáÍøÂ縺µ££»Äܹ»·Ö¿ªµÄ²Ù×÷¾¡Á¿·Ö¿ª´¦Àí£¬Ìá¸ßÿ´ÎµÄÏìÓ¦Ëٶȣ»ÔÚÊý¾Ý´°¿ÚʹÓÃSQLʱ£¬¾¡Á¿°ÑʹÓõÄË÷Òý·ÅÔÚÑ¡ÔñµÄÊ×ÁУ»Ëã·¨µÄ½á¹¹¾¡Á¿¼òµ¥£»ÔÚ²éѯʱ£¬²»Òª¹ý¶àµØʹÓÃͨÅä·ûÈçSELECT * from T1Óï¾ä£¬ÒªÓõ½¼¸ÁоÍÑ¡Ôñ¼¸ÁÐÈ磺SELECT COL1,COL2 from T1£»ÔÚ¿ÉÄܵÄÇé¿öϾ¡Á¿ÏÞÖƾ¡Á¿½á¹û¼¯ÐÐÊýÈ磺SELECT TOP 300 COL1,COL2,COL3 from T1,ÒòΪijЩÇé¿öÏÂÓû§ÊDz»ÐèÒªÄÇô¶àµÄÊý¾ÝµÄ¡£²»ÒªÔÚÓ¦ÓÃÖÐʹÓÃÊý¾Ý¿âÓα꣬ÓαêÊǷdz£ÓÐÓõŤ¾ß£¬µ«±ÈʹÓó£¹æµÄ¡¢ÃæÏò¼¯µÄSQLÓï¾äÐèÒª¸ü´óµÄ¿ªÏú£»°´ÕÕÌض¨Ë³ÐòÌáÈ¡Êý¾ÝµÄ²éÕÒ¡£
2¡¢   ±ÜÃâʹÓò»¼æÈݵÄÊý¾ÝÀàÐÍ¡£ÀýÈçfloatºÍint¡¢charºÍvarchar¡¢binaryºÍvarbinaryÊDz»¼æÈݵġ£Êý¾ÝÀàÐ͵IJ»¼æÈÝ¿ÉÄÜʹÓÅ»¯Æ÷ÎÞ·¨Ö´ÐÐһЩ±¾À´¿ÉÒÔ½øÐеÄÓÅ»¯²Ù×÷¡£ÀýÈç:
SELECT name from employee WHERE salary £¾ 60000
ÔÚÕâÌõÓï¾äÖÐ,Èçsalary×Ö¶ÎÊÇmoneyÐ͵Ä,ÔòÓÅ»¯Æ÷ºÜÄѶÔÆä½øÐÐÓÅ»¯,ÒòΪ60000ÊǸöÕûÐÍÊý¡£ÎÒÃÇÓ¦µ±ÔÚ±à³Ìʱ½«ÕûÐÍת»¯³ÉΪǮ±ÒÐÍ,¶ø²»ÒªµÈµ½ÔËÐÐʱת»¯¡£
3¡¢   ¾¡Á¿±ÜÃâÔÚWHERE×Ó¾äÖжÔ×ֶνøÐк¯Êý»ò±í´ïʽ²Ù×÷£¬Õ⽫µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£È磺
SELECT * from T1 WHERE F1/2=100
Ó¦¸ÄΪ:
SELECT * from T1 WHERE F1=100*2
SELECT * from RECORD WHERE SUBSTRING(CARD_NO,1,4)=’5378’
Ó¦¸ÄΪ:
SELECT * from RECORD WHERE CARD_NO LIKE ‘5378%’
SELECT member_number, first_name, last_name from members
WHERE DATEDIFF(yy,datofbirth,GETDATE()) > 21
Ó¦¸ÄΪ:
SELECT member_number, first_name, last_name from members
WHERE dateofbirth < DATEADD(yy,-21,GETDATE())
¼´£ºÈκζÔÁеIJÙ×÷¶¼½«µ¼Ö±íɨÃ裬Ëü°üÀ¨Êý¾Ý¿âº¯Êý¡¢¼ÆËã±í´ïʽµÈµÈ£¬²éѯʱҪ¾¡¿ÉÄܽ«²Ù×÷ÒÆÖÁµÈºÅÓұߡ£
4¡¢   ±ÜÃâʹÓÃ!=»ò£¼£¾¡¢IS NULL»òIS NOT NULL¡¢IN £¬NOT INµÈÕâÑùµÄ²Ù×÷·û,ÒòΪÕâ»áʹϵͳÎÞ·¨Ê¹ÓÃË÷Òý,¶øÖ»ÄÜÖ±½ÓËÑË÷±íÖеÄÊý¾Ý¡£ÀýÈç:
SELECT id from employee WHERE id != 'B%'
ÓÅ»¯Æ÷½«ÎÞ·¨Í¨¹ýË÷ÒýÀ´È·¶¨½«ÒªÃüÖеÄÐÐÊý,Òò´ËÐèÒªËÑË÷¸Ã±íµÄËùÓÐÐС£
5¡¢      ¾¡Á¿Ê¹ÓÃÊý×ÖÐÍ×ֶΣ¬Ò»²¿·Ö¿ª·¢ÈËÔ±ºÍÊý¾Ý¿â¹ÜÀíÈËԱϲ


Ïà¹ØÎĵµ£º

sqlµÄ¼¸¸öÅÅÐòº¯Êý

1ÓÃÓÚÅÅÐòµÄº¯Êý
row_number()
rank()
dense_rank()
ntile(group_number)
ÏÂÃæÁоÙÕâ¸öº¯ÊýµÄÓ÷¨£º
row_number()º¯ÊýÒ»°ãÓÃÓÚ×éÄÚÅÅÐò£¬¶øÆäËûÈý¸öº¯ÊýÊǶԽá¹û¼¯ÅÅÐò
Àý×Ó£º·ÖÒ³ÅÅÐò
<!--×¢ÒâÈ«¾Ö±äÁ¿Ò²ÔÚÕâÀïÉùÃ÷£¬²¢ÓöººÅ¸ô¿ª-->
create proc MyDividePageSort @iRowCount int ,@iPageNo int
AS
< ......

SQL¹ØÓÚÁ½±í¹ØÁªµÄupdate

¹ØÓÚÁ½±í¹ØÁªµÄupdate£¬µ«Óï¾äÔõôд¶¼²»ÕýÈ·£¬ÀÏÊDZ¨´í£¬ÓÚÊÇÐľªÈâÌø£¨¾ÍŲ»Äܼ°Ê±Íê³É²Ù×÷£©È¥²éÁËһϣ¬NND£¬Ô­À´°ÑSQLд³ÉÁËÔÚSQL ServerÏÂÃæµÄÌØÓÐÐÎʽ£¬ÕâÖÖÓï·¨ÔÚOracleÏÂÃæÊÇÐв»Í¨µÄ£¬¼±Ã¦¸Ä»ØÀ´£¬¼°Ê±Íê³ÉÁËÈÎÎñ¡£Ë³±ãÒ²°Ñ²éµ½µÄSQLÌû³öÀ´£¬ÄÄÌìÔÙÍü¼ÇÁË£¬Ò²ºÃÔÚÕâÀïÕÒ»ØÀ´£º
   update customers a ......

sqlÓï¾ä²éѯ±íµÄ×Ö¶ÎÃû

select name from syscolumns where id in (select id from sysobjects where type = 'u' and name = 'ÏàÓ¦±íÃû')  
ÓÃÒÔÉÏsqlÓï¾äÊäÈëÏàÓ¦±íÃû¾Í¿ÉÒԲ鵽±íµÄ×Ö¶ÎÃû£¬¶ÔÓ¦ºÃÊý¾Ý¿â ²éѯÊÇ·ñ´æÔڸñíÓï¾ä
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tb_cost]') and OBJECTPROPER ......

SQL ServerÈçºÎÌá¸ßÊý¾Ý¿â»¹Ô­µÄËÙ¶È

Ó°ÏìÊý¾Ý¿â»¹Ô­ËٶȵÄÒòËغÍÓ°ÏìÊý¾Ý¿â±¸·ÝËٶȵÄÒòËØÏàͬ¡£³ý´ËÖ®Í⣬¼ÙÈçÄãʹÓÃSQL Server 2005µÄ»°£¬Ä㻹¿ÉÒÔÆô¶¯ÁíÍâÒ»¸öÓÅ»¯ÈÎÎñÀ´»¹Ô­µ±Ç°²»´æÔÚµÄÊý¾Ý¿â£¬ÔËÐл·¾³ÎªWindows XP£¬Windows 2003 Server »ò¸üа汾¡£
Perform Volume Maintenance Tasks
µ±Ä㻹ԭһ¸öеÄÍêÕûÊý¾Ý¿âÊÇ£¬SQL Server¶Á±¸·ÝÎļþÍ·£¬È»ºó´ ......

SQL SERVER 2000/2005 ÁÐתÐÐ ÐÐתÁÐ


ÆÕͨÐÐÁÐת»»
ÎÊÌ⣺¼ÙÉèÓÐÕÅѧÉú³É¼¨±í(tb)ÈçÏÂ:
ÐÕÃû ¿Î³Ì ·ÖÊý
ÕÅÈý ÓïÎÄ 74
ÕÅÈý Êýѧ 83
ÕÅÈý ÎïÀí 93
ÀîËÄ ÓïÎÄ 74
ÀîËÄ Êýѧ 84
ÀîËÄ ÎïÀí 94
Ïë±ä³É(µÃµ½ÈçϽá¹û)£º
ÐÕÃû ÓïÎÄ Êýѧ ÎïÀí
---- ---- ---- ----
ÀîËÄ 74 84 94
ÕÅÈý 74 83 93
-------------------
*/
create table tb(Ð ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ