mysql sql °ÙÍò¼¶Êý¾Ý¿âÓÅ»¯·½°¸
1.¶Ô²éѯ½øÐÐÓÅ»¯£¬Ó¦¾¡Á¿±ÜÃâÈ«±íɨÃ裬Ê×ÏÈÓ¦¿¼ÂÇÔÚ where ¼° order by Éæ¼°µÄÁÐÉϽ¨Á¢Ë÷Òý¡£
2.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐÐ null ÖµÅжϣ¬·ñÔò½«µ¼ÖÂÒýÇæ
·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬È磺
select id from t where num is null
¿ÉÒÔÔÚnumÉÏÉèÖÃ
ĬÈÏÖµ0£¬È·±£±íÖÐnumÁÐûÓÐnullÖµ£¬È»ºóÕâ
Ñù²éѯ£º
select id from t where num=0
3.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖÐʹÓÃ!=»ò<>²Ù×÷·û£¬·ñÔò½«ÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£
4.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖÐʹÓà or À´Á¬½ÓÌõ¼þ£¬·ñÔò½«µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬È磺
select id from t where num=10 or num=20
¿ÉÒÔÕâÑù²éѯ£º
select id from t where num=10
union all
select id from t where num=20
5.in ºÍ not in Ò²ÒªÉ÷Ó㬷ñÔò»áµ¼ÖÂÈ«±íɨÃ裬È磺
select id from t where num in(1,2,3)
¶ÔÓÚÁ¬ÐøµÄÊýÖµ£¬ÄÜÓà between ¾Í²»ÒªÓà in ÁË£º
select id from t where num between 1 and 3
6.ÏÂÃæµÄ²éѯҲ½«µ¼ÖÂÈ«±íɨÃ裺
select id from t where name like ‘%abc%’
ÈôÒªÌá¸ßЧÂÊ£¬¿ÉÒÔ¿¼ÂÇÈ«ÎļìË÷¡£
7.Èç¹ûÔÚ where ×Ó¾äÖÐʹÓòÎÊý£¬Ò²»áµ¼ÖÂÈ«±íɨÃè¡£ÒòΪSQL
Ö»ÓÐÔÚÔËÐÐʱ²Å»á½âÎö
¾Ö²¿±äÁ¿£¬µ«ÓÅ»¯³ÌÐò
²»Äܽ«·ÃÎÊ
¼Æ»®µÄÑ¡ÔñÍƳٵ½ÔËÐÐʱ£»Ëü±ØÐëÔÚ±àÒë
ʱ½øÐÐÑ¡Ôñ¡£È»
¶ø£¬Èç¹ûÔÚ±àÒëʱ½¨Á¢·ÃÎʼƻ®£¬±äÁ¿µÄÖµ»¹ÊÇδ֪µÄ£¬Òò¶øÎÞ·¨×÷ΪË÷ÒýÑ¡ÔñµÄÊäÈëÏî¡£ÈçÏÂÃæÓï¾ä½«½øÐÐÈ«±íɨÃ裺
select id from t where [email=num=@num]num=@num[/email]
<[email=num=@num]mailto:num=@num[/email]>
¿ÉÒÔ¸ÄΪǿÖƲéѯʹÓÃË÷Òý£º
select id from t with(index(Ë÷ÒýÃû)) where [email=num=@num]num=@num[/email]
<[email=num=@num]mailto:num=@num[/email]>
8.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐбí´ïʽ²Ù×÷£¬Õ⽫µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£È磺
select id from t where num/2=100
Ó¦¸ÄΪ:
select id from t where num=100*2
9.Ó¦¾¡Á¿±ÜÃâÔÚwhere×Ó¾äÖжÔ×ֶνøÐк¯Êý
²Ù×÷£¬Õ⽫µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£
È磺
select id from t where substring(name,1,3)=’abc’–nameÒÔabc¿ªÍ·µÄid
select id from t where
datediff(day,createdate,’2005-11-30′)=0–‘2005-11-30’Éú³ÉµÄid
Ó¦¸ÄΪ:
select id from t where name like &lsquo
Ïà¹ØÎĵµ£º
ÓÃmysql_query£¬mysql_fetch_array()ºóÓ¦¸ÃÒª
free_result().function count_admin($where = '')
{
if($where) $where = " WHERE $where";
$result = $this->db->get_one("SELECT count(*) as num from $this->table_admin_role $where");
return $result['num'];
} ......
°²×°ÅäÖÃmysql
http://edu.codepub.com/2009/1213/18710.php
Ò»¡¢
ÏÂÔرàÒë°²×°
#cd /usr/local/src/
#wget http://mysql.byungsoo.net/Downloads/MySQL-5.1/mysql-5.1.38.tar.gz
#tar –xzvf mysql-5.1.38.tar.gz ../software/
#./configure
--prefix=/usr/local/mysql //MySQL°²×°Ä¿Â¼
--datadir=/mydata / ......
MySQLÊý¾Ý¿â±¸·ÝºÍ»¹ÔµÄ³£ÓÃÃüÁî
ÔÎļûhttp://www.21andy.com/blog/20071102/655.html
ʱ¼ä£º2007-11-02 23:29:09 Àà±ð£º¼¼Êõ ·ÃÎÊ£º3,731 views RSS 2.0 ÆÀÂÛ
±¸·ÝMySQLÊý¾Ý¿âµÄÃüÁî
mysqldump -hhostname -uusername -ppassword database ......
¼¸¸ö³£ÓÃÓÃÀý£º
1.µ¼³öÕû¸öÊý¾Ý¿â mysqldump -u Óû§Ãû -p Êý¾Ý¿âÃû > µ¼³öµÄÎļþÃû mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql2.µ¼³öÒ»¸ö±í mysqldump -u Óû§Ãû -p Êý¾Ý¿âÃû ±íÃû> µ¼³öµÄÎļþÃû mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql3.µ¼³öÒ»¸öÊý¾Ý¿â½ ......
select top Ò³´óС *
from table1
where id>
(select max (id) from
(select top ((Ò³Âë-1)*Ò³´óС) id from table1 order by id) as T) order by id ......