һЩ¼òµ¥µÄmysql SQLÓï¾ä±¸Íü
·ÅÔÚÕâÀﱸÍü,ÀÏÊÇÍü¼ÇÔõôд¡£
mysql> create database book;
mysql> use book;
Database changed
mysql> create table email_message(key_mail_messages INTEGER,
-> date_created VARCHAR(19),
-> date_updated varchar(19),
-> date_email varchar(19),
-> addr_from varchar(100),
-> addr_reply_to varchar(100),
-> subject varchar(100),
-> message mediumtext);
mysql> describe email_message;
+-------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+-------+
| key_mail_messages | int(11) | YES | | NULL | |
| date_created | varchar(19) | YES | | NULL | |
| date_updated | varchar(19) | YES | | NULL | |
| date_email | varchar(19) | YES | | NULL | |
| addr_from | varchar(100) | YES | | NULL | |
| addr_reply_to | varchar(100) | YES | | NULL | |
| subject | varchar(100) | YES | | NULL | |
| message | mediumtext | YES | | NULL | |
+-------------------+--------------+------+-----+---------+-------+
mysql> alter table email_message add column temp_field integer;
mysql> describe email_message;
+-------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+-------+
| key_mail_messages | int(11) | YES | | NULL | |
| date_created | varchar(19) | YES | | NULL | |
| date_updated | varchar(19) | YES | | NULL | |
| date_email | varchar(19) | YES | | NULL | |
| addr_from | varchar(100) | YES | | NULL | |
| addr_reply_to | varchar(100) | YES |
Ïà¹ØÎĵµ£º
½éÉÜGROUP BY ºÍ HAVING ×Ó¾äǰ£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý:¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
SELECT SUM(population) from bbc
ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéѯֻ·µ»ØÒ»¸ö½á¹û£¬¼´ËùÓйú¼ÒµÄ×ÜÈË¿ ......
ÓÉÓÚ³ÌÐòÐèÒª°ÑSQL SERVER ÀïµÄÊý¾Ýµ¼Èëµ½ACCESSÀï.
¸Õ¿ªÊ¼Ê¹ÓÃDataSetÀ´Ñ»·.
Êý¾ÝÁ¿ÉÙµÄʱºò»¹Ëã¿ÉÒÔÓ¦¸¶µÄ¹ýÀ´.
µ«µ±Êý¾Ý¶àµÄʱºò.
»á±¨´í"λÖôíÎó"
ÔÚÍøÉÏËÑѰһ·¬.ÕÒµ½Ò»¸ö·½·¨.
ʹÓÃinsert into openrowset
½Ó×Å´íÎóÒ»¸ö½ÓÒ»¸öµÄÀ´..
"²åÈë´íÎó: ÁÐÃû»òËùÌṩֵµÄÊýÄ¿Óë±í¶¨Ò岻ƥÅä¡£"
"δÄÜÕÒµ½ OLE DB Ì ......
/*sqlÖØ¸´Êý¾Ý´¦Àí£¬ÓÐΨһID£¬formidÓÐÖØ¸´*/
/*²é³öÖØ¸´µÄfromid*/
select formid from GaiaSaver_BUG group by formid having count(*)>1
/*ɾ³ýÖØ¸´formid£¬Ö»ÁôÒ»Ìõ*/
delete from GaiaSaver_BUG where ID not in
(select min(ID) as ID from GaiaSaver_BUG group by for ......
¶øÕâһƪÖУ¬ÎÒÃǾÍÎ§ÈÆSQLÓÅ»¯À´¿ªÊ¼Õâ´Î½²½â£¬ÎªÊ²Ã´µÚÒ»½²ÒªËµSQLÓÅ»¯£¿ÒòΪÎÒÈÏΪÕâÊdzÌÐòÔ±µÄ»ù±¾¹¦£¬¶øÇÒÒ²ÊÇÎÒÃDZØÐëÒªÈ¥ÕÆÎյģ¬ËäÈ»ÄãдµÄ SQLÓï¾äÄÜÍê³ÉÏàÓ¦µÄ¹¦ÄÜ£¬µ«ÊÇÄãÊÇ·ñ¿¼ÂǹýÕâЩÓï¾äÅöµ½º£Á¿Êý¾Ý»òÕß±©Á¦·ÃÎÊʱ»á²»»á´øÀ´Ð§ÂʵĴó·ù¶ÈµÄ¼õÂý£¿Ò²ÐíºÜ¶à³ÌÐòÔ±ºÍÎÒÒ»ÑùÔÚÅöµ½ÏµÍ³ÏìÓ¦Ê ......
1.¶àwhere£¬ÉÙhaving
whereÓÃÀ´¹ýÂËÐУ¬havingÓÃÀ´¹ýÂË×é
2.¶àunion all£¬ÉÙunion
unionɾ³ýÁËÖØ¸´µÄÐУ¬Òò´Ë»¨·ÑÁËһЩʱ¼ä
3.¶àExists£¬ÉÙin
ExistsÖ»¼ì²é´æÔÚÐÔ£¬ÐÔÄܱÈinÇ¿ºÜ¶à£¬ÓÐЩÅóÓѲ»»áÓÃExists£¬¾Í¾Ù¸öÀý×Ó
Àý£¬ÏëÒªµÃµ½Óе绰ºÅÂëµÄÈ˵Ļù±¾ÐÅÏ¢£¬table2ÓÐÈßÓàÐÅÏ¢
select * from table1;--(id,n ......