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
Ïà¹ØÎĵµ£º
Some problems encounted this afternoon, when trying to setup/test mysql capabilities on hypnos and virgil.
1.ERROR 2003 (HY000): Can't connect to MySQL server on 'server-name' (111)
access locally (i.e. from localhost) is fine, when trying remotely got this error. when tried with mysql++ library, ......
×òÌìÒªmysqlÖÐд´æ´¢¹ý³Ì·¢ÏÖÍøÉÏÓйØÓÚcursorÑ»·ÇÒÌ×µÄ×ÊÁϺÜÉÙ,ÏÖ·¢³ö±¾ÈËдµÄÀý×Ó,Ï£ÍûÄܶԴó¼ÒÓаïÖú.
¿´ÕÐ:
DELIMITER $$
USE `ad_db`$$
DROP PROCEDURE IF EXISTS `test`$$
CREATE DEFINER=`root`@`%` PROCEDURE `test`()
BEGIN
/** CPAЧ¹ûÊý */
DECLARE _tmpId1 INT;
DECLARE ......
×òÌìÓиö¹¦ÄÜҪʵÏÖÅÅÐÐЧ¹û£¬¶øÇÒÊÇËæ»ú°´ÕÕijЩ×ֶεÄ×ÜÖµ£¬µ«ÊǵÚÒ»¸öÓÖÒª²»Ò»Ñù£¬ÒòΪµÚÒ»¸öÈ˸øÁËÇ®£¬ËùÒÔÒªÅŵÚÒ»¡£
´ò¸ö±È·½°É£¬±í(userinfo)ÖÐÓÐÕ⼸¸ö×ֶΣºusername,isvalid,givedmoney,sumip,dayip,monthip,visitcount,regdate
ÏÖÔÚҪʵÏÖÏÔʾÅÅÐÐǰ10λÓû§£¬
³öÏÖÔÚÅÅÐеÚһλµ ......
delete from
uservalid
where(lastlogin<'2007-1-1
0:0:00')
Çå³ýÔÚuservalid±íÖÐ×îºóµÇ½ʱ¼äÔÚ2007Äê1ÔÂ1ÈÕÁãʱÁã·Ö֮ǰµÄÊý¾Ý
²éѯijһ·¶Î§ÄÚµÄÊý¾ÝÔòselete * from uservalid
where(wealth in(500,1000))
ÔÚ²éѯ·ÖÎöÆ÷ÀïÃæselete from where
inÕâЩ¹Ø¼ü×Ö¶¼×Ô¶¯´óдÁË
......