×ܽá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"ʾÀý£º
¡¡¡¡×ݱí½á¹¹:
¡¡¡¡
¡¡¡¡fname ftype fvalue
¡¡¡¡Ð¡ÇÇ zaocan 10
¡¡¡¡Ð¡ÇÇ zhongcan 20
¡¡¡¡Ð¡ÇÇ wancan 5
¡¡¡¡
¡¡¡¡×ª»»ºóµÄ±í½á¹¹:
¡¡¡¡
¡¡¡¡fname zaocan_value zhongcan_value wancan_value
¡¡¡¡Ð¡ÇÇ 10 20 5
¡¡¡¡
¡¡¡¡×ݱíתºá±íSQLʾÀý:
¡¡¡¡
¡¡¡¡select Fname, sum(case ......
×î½üÓöµ½Ò»¸öÎÊÌ⣬ÔÚ²Ù×÷SQL¸üÐÂÕË»§Óà¶îʱ£¬³£³£·¢ÏÖ¸üкóµÄÓà¶îÓëʵ¼ÊµÄ²»Ïà·û£¬ÂíÉÏÏëµ½ÁËÊDz»ÊÇ´æÔÚ²¢·¢¸üУ¬Ò»²é¹ûÈ»Èç´Ë¡£Ö®Ç°Ò²ÔøÓöµ½¹ýÕâÑùµÄÎÊÌ⣬µ±Ê±Ã»Ì«ÔÚÒ⣬ÏÖÔÚÊǽâ¾öµÄʱºòÁË¡£ÓÃMysqlÄ£ÄâÁËÒ»ÏÂÕâ¸ö¹ý³Ì£º´´½¨Á½ÕÅ±í£¬paralltableºÍparallalter£¬Ã¿´Î¸ù¾Ýparatable±í¸üÐÂparallalte ......
ÔÚƽʱµÄ¹¤×÷¹ý³ÌÖУ¬×÷ΪDBA½ÇÉ«¹ÜÀíÊý¾Ý¿â£¬Í·ÄÔÖеÄÓ¡ÏóÍùÍùÊÇÊý¾Ý¿âʵÀýÃû³Æ£¬¶ø²»»áÈ¥¹ØÐÄServerµÄIP£¬¶ø×÷ΪDeveloperµÄ½ÇÉ«£¬ËûÃÇÍùÍùÏëÖªµÀÖªµÀServer IpºÍ¶Ë¿ÚºÅ¡£ËùÒÔ£¬DBA»á¾³£±»Îʼ°µ½£ºXXXʵÀýµÄIPºÍ¶Ë¿ÚºÅÊÇʲô£¿
Õâ¸öÎÊÌ⣬µ±È»ÎÒÃÇ¿ÉÒÔLoginµ½OS²é¿´IP¡¢Ê¹ÓÃÅäÖƹÜÀí¹¤¾ß»ñÈ¡µ½¶Ë¿ÚºÅ¡£µ«ÊÇ£¬Õâ¸ö·½·¨·Ç ......
ÊÓͼ²Ù×÷
ÊÓͼÊÇ´ÓÒ»¸ö»òÕ߶à¸ö±í»òÊÓͼÖе¼³öµÄ±í£¬Æä½á¹¹ºÍÊý¾ÝÊǽ¨Á¢ÔÚ¶Ô±íµÄ²éѯ»ù´¡Éϵġ£ÓëÕæʵµÄ±íÒ»Ñù£¬ÊÓͼҲ°üÀ¨¼¸¸ö±»¶¨ÒåµÄÊý¾ÝÁкͶà¸öÊý¾ÝÐУ¬µ«ÕâЩÊý¾Ýʵ¼ÊÉÏÊDZ»ÆäÒýÓõÄÆäËû±íÖеÄÊý¾Ý¡£Òò´Ë£¬ÊÓͼ²»ÊÇÕæʵ´æÔڵĻù´¡±í£¬¶øÊÇÒ»¸öÐéÄâµÄ±í£¬ÊÓͼËù¶ÔÓ¦µÄÊý¾Ý²¢²»Êµ¼ÊµØÒÔÊÓͼ½á¹¹´æ´¢ÔÚÊý¾Ý¿âÖУ¬¶øÊÇ´æ ......