sqlÖÐwhereºóÃæ¿ÉÒÔ¸úʲôÔËËã
where ×Ó¾äʹÓÃÔËËã·ûƾ֤Ìõ¼þ¹ýÂËÊý¾Ý¿â¼Í¼£¬°üÀ¨½ÏÁ¿£¨=¡¢¡¢>¡¢=¡¢
SQL ÖÐ WHERE ×Ó¾äºóµÄÔËËã·û
WHERE ×Ó¾äÓÃÓÚƾָ֤¶¨µÄÌõ¼þ¹ýÂËÊý¾Ý¿â±íÖеļͼ¡£ËüÖ§³ÖʹÓÃÆÕ±éµÄÔËËã·ûÀ´½ÏÁ¿×Ö¶ÎÖµ²¢È·¶¨Òª±£´æµÄ¼Í¼¡£
½ÏÁ¿ÔËËã·û
¼´ÊÇ (=)
²»¼´ÊÇ ( »ò !=)
´óÓÚ (>)
СÓÚ (
´óÓÚ¼´ÊÇ (>=)
СÓÚ¼´ÊÇ (
Âß¼ÔËËã·û
Óë (AND)£º·µ»Øͬʱ֪×ãÁ½¸öÌõ¼þµÄ¼Í¼¡£
»ò (OR)£º·µ»ØÖª×ãÈκÎÒ»¸öÌõ¼þµÄ¼Í¼¡£
·Ç (NOT)£º·µ»Ø²»Öª×ãÖ¸¶¨Ìõ¼þµÄ¼Í¼¡£
²¼¶ûÔËËã·û
Õæ (TRUE)£º·µ»ØÕæÖµ¡£
¼Ù (FALSE)£º·µ»Ø¼ÙÖµ¡£
δ֪ (NULL)£ºÌåÏÖ¸Ãֵδ֪»ò²»±£´æ¡£
¹æÄ£ÔËËã·û
BETWEEN£º·µ»Ø½éÓÚÖ¸¶¨¹æÄ£Äڵļͼ¡£
IN£º·µ»ØֵλÓÚÖ¸¶¨ÁбíÖеļͼ¡£
×Ö·û´®ÔËËã·û
LIKE£º·µ»ØÓëÖ¸¶¨Ä£Ê½Æ¥ÅäµÄ¼Í¼¡£
NOT LIKE£º·µ»Ø²»ÓëÖ¸¶¨Ä£Ê½Æ¥ÅäµÄ¼Í¼¡£
%£ºÍ¨Åä·û£¬ÌåÏÖÈκÎ×Ö·ûÐòÁС£
_£ºÍ¨Åä·û£¬ÌåÏÖÈκε¥¸ö×Ö·û¡£
ÆäËûÔËËã·û
IS NULL£º·µ»ØֵΪ NULL µÄ¼Í¼¡£
IS NOT NULL£º·µ»ØÖµ²»Îª NULL µÄ¼Í¼¡£
EXISTS£º×ÓÅÌÎÊ·µ»ØÖÁÉÙÒ»Ìõ¼Í¼ʱ£¬·µ»ØÕæ¡£
NOT EXISTS£º×ÓÅÌÎÊûÓзµ»ØÈκμͼʱ£¬·µ»ØÕæ¡£
ʹÓÃʾÀý
SELECT * FROM users WHERE id = 1; -- ʹÓü´ÊÇÔËËã·û SELECT * FROM orders WHERE total > 100; -- ʹÓôóÓÚÔËËã·û SELECT * FROM products WHERE category = 'Electronics' OR category = 'Gadgets'; -- ʹÓûòÔËËã·û SELECT * FROM customers WHERE name LIKE '%John%'; -- ʹÓà LIKE ÔËËã·û SELECT * FROM posts WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31'; -- ʹÓà BETWEEN ÔËËã·û
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇsqlÖÐwhereºóÃæ¿ÉÒÔ¸úʲôÔËËãµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡