×ܽá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 ²åÈëµ½Êý¾Ý¿âµÄ×îºóÒ»ÐеÄÐбêʶ·û£¨É
Ïà¹ØÎĵµ£º
×î½üÓöµ½Ò»¸öÎÊÌ⣬ÔÚ²Ù×÷SQL¸üÐÂÕË»§Óà¶îʱ£¬³£³£·¢ÏÖ¸üкóµÄÓà¶îÓëʵ¼ÊµÄ²»Ïà·û£¬ÂíÉÏÏëµ½ÁËÊDz»ÊÇ´æÔÚ²¢·¢¸üУ¬Ò»²é¹ûÈ»Èç´Ë¡£Ö®Ç°Ò²ÔøÓöµ½¹ýÕâÑùµÄÎÊÌ⣬µ±Ê±Ã»Ì«ÔÚÒ⣬ÏÖÔÚÊǽâ¾öµÄʱºòÁË¡£ÓÃMysqlÄ£ÄâÁËÒ»ÏÂÕâ¸ö¹ý³Ì£º´´½¨Á½ÕÅ±í£¬paralltableºÍparallalter£¬Ã¿´Î¸ù¾Ýparatable±í¸üÐÂparallalte ......
ÔÚ½éÉÜGROUP BY ºÍ HAVING ×Ó¾äÇ°£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý£º¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
SELECT SUM(population) from bbc
¡¡¡¡ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéÑ ......
ÔÚƽʱµÄ¹¤×÷¹ý³ÌÖУ¬×÷ΪDBA½ÇÉ«¹ÜÀíÊý¾Ý¿â£¬Í·ÄÔÖеÄÓ¡ÏóÍùÍùÊÇÊý¾Ý¿âʵÀýÃû³Æ£¬¶ø²»»áÈ¥¹ØÐÄServerµÄIP£¬¶ø×÷ΪDeveloperµÄ½ÇÉ«£¬ËûÃÇÍùÍùÏëÖªµÀÖªµÀServer IpºÍ¶Ë¿ÚºÅ¡£ËùÒÔ£¬DBA»á¾³£±»Îʼ°µ½£ºXXXʵÀýµÄIPºÍ¶Ë¿ÚºÅÊÇʲô£¿
Õâ¸öÎÊÌ⣬µ±È»ÎÒÃÇ¿ÉÒÔLoginµ½OS²é¿´IP¡¢Ê¹ÓÃÅäÖƹÜÀí¹¤¾ß»ñÈ¡µ½¶Ë¿ÚºÅ¡£µ«ÊÇ£¬Õâ¸ö·½·¨·Ç ......
Ë÷Òý²Ù×÷
Êý¾Ý¿âÖеÄË÷ÒýÓëÊé¼®ÖеÄË÷ÒýÀàËÆ£¬ÔÚÒ»±¾ÊéÖУ¬ÀûÓÃË÷Òý¿ÉÒÔ¿ìËÙ²éÕÒËùÐèÐÅÏ¢£¬ÎÞÐëÔĶÁÕû±¾Êé¡£ÔÚÊý¾Ý¿âÖУ¬Ë÷ÒýʹÊý¾Ý¿â³ÌÐòÎÞÐë¶ÔÕû¸ö±í½øÐÐɨÃ裬¾Í¿ÉÒÔÔÚÆäÖÐÕÒµ½ËùÐèÊý¾Ý¡£ÊéÖеÄË÷ÒýÊÇÒ»¸ö´ÊÓïÁÐ±í£¬ÆäÖÐ×¢Ã÷Á˸÷¸ö´ÊµÄÒ³Âë¡£¶øÊý¾Ý¿âÖеÄË÷ÒýÊÇij¸ö±íÖÐÒ»ÁлòÕßÈô¸ÉÁÐÖµµÄ¼¯ºÏ£¬ºÍÏàÓ¦µÄÖ¸Ïò±íÖÐÎïÀí±ê ......
ÊÓͼ²Ù×÷
ÊÓͼÊÇ´ÓÒ»¸ö»òÕ߶à¸ö±í»òÊÓͼÖе¼³öµÄ±í£¬Æä½á¹¹ºÍÊý¾ÝÊǽ¨Á¢ÔÚ¶Ô±íµÄ²éѯ»ù´¡Éϵġ£ÓëÕæʵµÄ±íÒ»Ñù£¬ÊÓͼҲ°üÀ¨¼¸¸ö±»¶¨ÒåµÄÊý¾ÝÁкͶà¸öÊý¾ÝÐУ¬µ«ÕâЩÊý¾Ýʵ¼ÊÉÏÊDZ»ÆäÒýÓõÄÆäËû±íÖеÄÊý¾Ý¡£Òò´Ë£¬ÊÓͼ²»ÊÇÕæʵ´æÔڵĻù´¡±í£¬¶øÊÇÒ»¸öÐéÄâµÄ±í£¬ÊÓͼËù¶ÔÓ¦µÄÊý¾Ý²¢²»Êµ¼ÊµØÒÔÊÓͼ½á¹¹´æ´¢ÔÚÊý¾Ý¿âÖУ¬¶øÊÇ´æ ......