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

×ܽáSQLite²»Ö§³ÖµÄSQLÓï·¨ÓÐÄÄЩ


1 TOP
ÕâÊÇÒ»¸ö´ó¼Ò¾­³£Îʵ½µÄÎÊÌ⣬ÀýÈçÔÚSQLSERVERÖпÉÒÔʹÓÃÈçÏÂÓï¾äÀ´È¡µÃ¼Ç¼¼¯ÖеÄÇ°Ê®Ìõ¼Ç¼£º
SELECT TOP 10 * from [index] ORDER BY indexid DESC;
 
µ«ÊÇÕâÌõSQLÓï¾äÔÚSQLiteÖÐÊÇÎÞ·¨Ö´Ðеģ¬Ó¦¸Ã¸ÄΪ£º
SELECT * from [index] ORDER BY indexid DESC limit 0,10;
 
ÆäÖÐlimit 0,10±íʾ´ÓµÚ0Ìõ¼Ç¼¿ªÊ¼£¬ÍùºóÒ»¹²¶ÁÈ¡10Ìõ
 
2 ´´½¨ÊÓͼ£¨Create View£©
SQLiteÔÚ´´½¨¶à±íÊÓͼµÄʱºòÓÐÒ»¸öBUG£¬ÎÊÌâÈçÏ£º
CREATE VIEW watch_single AS SELECT DISTINCT watch_item.[watchid],watch_item.[itemid] from watch_item;
 
ÉÏÃæÕâÌõSQLÓï¾äÖ´Ðкó»áÏÔʾ³É¹¦£¬µ«ÊÇʵ¼ÊÉϳýÁË
SELECT COUNT(*) from [watch_single ] WHERE watch_ single.watchid = 1;
ÄÜÖ´ÐÐÖ®ÍâÊÇÎÞ·¨Ö´ÐÐÆäËûÈκÎÓï¾äµÄ¡£ÆäÔ­ÒòÔÚÓÚ½¨Á¢ÊÓͼµÄʱºòÖ¸¶¨ÁË×Ö¶ÎËùÔڵıíÃû£¬¶øSQLite²¢²»ÄÜÕýÈ·µØʶ±ðËü¡£ËùÒÔÉÏÃæµÄ´´½¨Óï¾äÒª¸ÄΪ£º
CREATE VIEW watch_single AS SELECT DISTINCT [watchid],[itemid] from watch_item;
 
µ«ÊÇËæÖ®¶øÀ´µÄÎÊÌâÊÇÈç¹ûÊǶà±íµÄÊÓͼ£¬ÇÒ±í¼äÓÐÖØÃû×ֶεÄʱºò¸ÃÔõô°ì£¿
 
3 COUNT£¨DISTINCT column£©
SQLiteÔÚÖ´ÐÐÈçÏÂÓï¾äµÄʱºò»á±¨´í£º
SELECT COUNT(DISTINCT watchid) from [watch_item] WHERE watch_item.watchid = 1;
ÆäÔ­ÒòÊÇSQLiteµÄËùÓÐÄÚÖú¯Êý¶¼²»Ö§³ÖDISTINCTÏÞ¶¨£¬ËùÒÔÈç¹ûҪͳ¼Æ²»Öظ´µÄ¼Ç¼ÊýµÄʱºò»á³öÏÖһЩÂé·³¡£±È½Ï¿ÉÐеÄ×ö·¨ÊÇÏȽ¨Á¢Ò»¸ö²»Öظ´µÄ¼Ç¼±íµÄÊÓͼ£¬È»ºóÔÙ¶Ô¸ÃÊÓͼ½øÐмÆÊý¡£
 
4 ÍâÁ¬½Ó
ËäÈ»SQLite¹Ù·½ÒѾ­Éù³ÆLEFT OUTER JOIN ÒѾ­ÊµÏÖ£¬µ«»¹Ã»ÓÐ RIGHT OUTER JOIN ºÍ FULL OUTER JOIN¡£µ«ÊÇʵ¼Ê²âÊÔ±íÃ÷Ëƺõ²¢²»Äܹ»Õý³£µÄ¹¤×÷¡£ÒÔÏÂÈýÌõÓï¾äÔÚÖ´ÐеÄʱºò¾ù»á±¨´í£º
SELECT tags.[tagid] from [tags],[tag_rss] WHERE tags.[tagid] = tag_rss.[tagid](*);
 
SELECT tags.[tagid] from [tags],[tag_rss] WHERE LEFT OUTER JOIN tag_rss.[tagid] = tags.[tagid];
 
SELECT tags.[tagid] from [tags],[tag_rss] WHERE LEFT JOIN tag_rss.[tagid] = tags.[tagid];
 
´ËÍâ¾­¹ý²âÊÔÓÃ+ºÅ´úÌæ*ºÅÒ²ÊDz»¿ÉÐеġ£
ÊÕ¼¯SQLiteÓëSql ServerµÄÓï·¨²îÒì
1.·µ»Ø×îºó²åÈëµÄ±êʶֵ
·µ»Ø×îºó²åÈëµÄ±êʶֵsql serverÓÃ@@IDENTITY
sqliteÓñêÁ¿º¯ÊýLAST_INSERT_ROWID()
·µ»Øͨ¹ýµ±Ç°µÄ SQLConnection ²åÈëµ½Êý¾Ý¿âµÄ×îºóÒ»ÐеÄÐбêʶ·û£¨É


Ïà¹ØÎĵµ£º

dz̸SQL½Ì³ÌÖ®Group byºÍHaving

ÔÚ½éÉÜGROUP BY ºÍ HAVING ×Ó¾äÇ°£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý£º¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
      SELECT SUM(population) from bbc
¡¡¡¡ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéÑ ......

SQL֪ʶ´óÔÓ»â


$$$Ϊÿ½ÚµÄ¿ªÊ¼
-------------------------------------------------------------------------------------------------------------------------------------------------
$$$ SQLÖÐϵͳÁÙʱ±íµÄʹÓúͽû¼É ¼° Exec(SQLScript) µÄʹÓÃ
ÒÔÇ°ÔÚSQL ÖÐдSP ʱ£¬Èç±È½Ï¸´ÔÓʱ£¬Ï²»¶ÖмäʹÓÃÁÙʱ±íÀ´ÔÝ´æÏà¹Ø¼Ç¼£¬ÕâÑùµÄ ......

SQL SERVER ͼ±íÊý¾Ý¿â

ͼ±í
ͼ±í(ÓֳƹØϵͼ)ÊÇSQL ServerÖÐÒ»ÀàÌØÊâµÄÊý¾Ý¿â¶ÔÏó£¬ËüÌṩ¸øÓû§Ö±¹ÛµØ¹ÜÀíÊý¾Ý¿â±íµÄ·½·¨¡£Í¨¹ýͼ±í£¬Óû§¿ÉÒÔÖ±¹ÛµØ´´½¨¡¢±à¼­Êý¾Ý¿â±íÖ®¼äµÄ¹Øϵ£¬Ò²¿ÉÒԱ༭±í¼°ÆäÁеÄÊôÐÔ¡£ÀûÓÃÆóÒµ¹ÜÀíÆ÷´´½¨Í¼±íµÄ¾ßÌå²½ÖèÈçÏ£º
(1)ÔÚÆóÒµ¹ÜÀíÆ÷ÖУ¬Õ¹¿ªÖ¸¶¨µÄ·þÎñÆ÷ºÍÊý¾Ý¿â£¬´ò¿ªÒª½¨Á¢µÄͼ±íËùÔÚµÄÊý¾Ý¿â£¬ÓÒ»÷ͼ±íÍ ......

SQL SERVER ÊÓͼ²Ù×÷Êý¾Ý¿â

ÊÓͼ²Ù×÷
ÊÓͼÊÇ´ÓÒ»¸ö»òÕ߶à¸ö±í»òÊÓͼÖе¼³öµÄ±í£¬Æä½á¹¹ºÍÊý¾ÝÊǽ¨Á¢ÔÚ¶Ô±íµÄ²éѯ»ù´¡Éϵġ£ÓëÕæʵµÄ±íÒ»Ñù£¬ÊÓͼҲ°üÀ¨¼¸¸ö±»¶¨ÒåµÄÊý¾ÝÁкͶà¸öÊý¾ÝÐУ¬µ«ÕâЩÊý¾Ýʵ¼ÊÉÏÊDZ»ÆäÒýÓõÄÆäËû±íÖеÄÊý¾Ý¡£Òò´Ë£¬ÊÓͼ²»ÊÇÕæʵ´æÔڵĻù´¡±í£¬¶øÊÇÒ»¸öÐéÄâµÄ±í£¬ÊÓͼËù¶ÔÓ¦µÄÊý¾Ý²¢²»Êµ¼ÊµØÒÔÊÓͼ½á¹¹´æ´¢ÔÚÊý¾Ý¿âÖУ¬¶øÊÇ´æ ......

SQLÖг£¼ûº¯ÊýµÄÓ÷¨

1Replaceº¯Êý
ÔÚSQL SERVER 2000ÖÐÓÐÒ»¸öÐÅÏ¢±í£¬´æ·ÅÐÂÎÅÐÅÏ¢£¬ÏÖÔÚ¿Í»§ÏëÅúÁ¿¸üÐÂÕâ¸ö×Ö¶ÎÖеÄijЩÎÄ×Ö£¬Ì滻ΪÆäËûÎÄ×Ö¡£
½â¾ö·½·¨£ºÀûÓÃreplaceº¯Êý
update detail set content=replace(content,'Ô­ÎÄ×Ö','Ìæ»»ºóÎÄ×Ö') where Ìõ¼þ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ