sqlÖÐʹÓÃ×Ó¾äºÍÖ÷¾äµÄÇø±ð
×Ó¾äÌṩ¸½¼ÓÐÅÏ¢»òÏÞÖÆ£¬ÀýÈçɸѡÊý¾ÝÌõ¼þ¡¢·Ö×éɸѡÌõ¼þºÍÅÅÐò˳Ðò¡£Ö÷¾ä½ç˵Óï¾äµÄÖ÷Òª²Ù×÷£¬°üÀ¨¼ìË÷Êý¾Ý¡¢²åÈëÐÂÐС¢¸üÐÂÏÖÓÐÐкÍɾ³ýÐС£×Ó¾äͨ³£Î»ÓÚÖ÷¾äÖ®ºó¡£
SQLÖеÄ×Ó¾äÓëÖ÷¾ä
ÔÚSQLÓï¾äÖУ¬¾ä·¨½á¹¹·ÖΪ×Ó¾äºÍÖ÷¾ä¡£×Ó¾äÊÇÓï¾äµÄÒ»²¿·Ö£¬Ìṩ¸½¼ÓÐÅÏ¢»òÏÞÖÆ£¬¶øÖ÷¾äÊǽç˵Óï¾äµÄÖ÷Òª²Ù×÷¡£
×Ó¾ä
WHERE×Ӿ䣺ָ¶¨É¸Ñ¡Êý¾ÝµÄÌõ¼þ¡£ËüÓÃÓÚ´Ó±íÖÐÑ¡ÔñÇкÏÌض¨Ìõ¼þµÄÐС£ÀýÈ磺
SELECT * FROM students WHERE age > 18;
µÇ¼ºó¸´ÖÆ
HAVING×Ӿ䣺¶Ô×éЧ¹ûÓ¦ÓÃɸѡÌõ¼þ¡£ËüÓÃÓÚ¹ýÂËÓÉGROUP BY×Ӿ䱬·¢µÄ×é¡£ÀýÈ磺
SELECT department, SUM(salary) AS total_salary FROM employees GROUP BY department HAVING total_salary > 50000;
µÇ¼ºó¸´ÖÆ
ORDER BY×Ӿ䣺ָ¶¨Ð§¹û¼¯µÄÅÅÐò˳Ðò¡£ËüÓÃÓÚƾ֤һ¸ö»ò¶à¸öÁжÔЧ¹û¾ÙÐÐÉýÐò»ò½µÐòÅÅÐò¡£ÀýÈ磺
SELECT * FROM products ORDER BY price DESC;
µÇ¼ºó¸´ÖÆ
Ö÷¾ä
SELECTÓï¾ä£ºÓÃÓÚ´Ó±íÖмìË÷Êý¾Ý¡£ËüÖ¸¶¨Òª´Ó±íÖÐÌáÈ¡µÄÁС£ÀýÈ磺
SELECT name, email FROM customers;
µÇ¼ºó¸´ÖÆ
INSERTÓï¾ä£ºÓÃÓÚÏò±íÖвåÈëÐÂÐС£ËüÖ¸¶¨ÁÐÃûºÍÒª²åÈëµÄÖµ¡£ÀýÈ磺
INSERT INTO products (name, price) VALUES ('iPhone 13', 999);
µÇ¼ºó¸´ÖÆ
UPDATEÓï¾ä£ºÓÃÓÚ¸üбíÖÐÏÖÓÐÐС£ËüÖ¸¶¨Òª¸üеÄÁкÍÐÂÖµ¡£ÀýÈ磺
UPDATE customers SET email = 'new_email@example.com' WHERE id = 1;
µÇ¼ºó¸´ÖÆ
DELETEÓï¾ä£ºÓÃÓÚ´Ó±íÖÐɾ³ýÐС£ËüÖ¸¶¨ÒªÉ¾³ýµÄÐС£ÀýÈ磺
DELETE FROM products WHERE discontinued = true;
µÇ¼ºó¸´ÖÆ
Çø±ð
¼ò¶øÑÔÖ®£¬×Ó¾äÌṩ¸½¼ÓÌõ¼þ»òÏÞÖÆ£¬¶øÖ÷¾ä½ç˵Óï¾äµÄÖ÷Òª²Ù×÷¡£×Ó¾äͨ³£Î»ÓÚÖ÷¾äÖ®ºó£¬¶øÖ÷¾ä±ØÐè±£´æ²Å»ªÖ´ÐÐÅÌÎÊ¡£
ÒÔÉϾÍÊÇsqlÖÐʹÓÃ×Ó¾äºÍÖ÷¾äµÄÇø±ðµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡