sqlÖÐasµÄÒâ˼
sql ÖÐ as Òªº¦×ÖÓÃÓÚ·ÖÅÉÓÖÃû»ò×ÓÅÌÎʵÄÃû³Æ£¬´Ó¶øÌṩÒÔÏÂÀûÒ棺Ìá¸ßÅÌÎʿɶÁÐÔ£¬·ÖÅɸü¾ßÐÎòÐÔµÄÓÖÃû¡£¼ò»¯ÖØ´óÅÌÎÊ£¬¸ø×ÓÅÌÎÊ·ÖÅÉÓÖÃû¡£±ÜÃâÃû³Æ³åÍ»£¬×èÖ¹±í»òÁÐÃû³ÆÖظ´Ôì³ÉµÄ³åÍ»¡£
SQL ÖÐ AS µÄ¼ÄÒå
SQL ÖÐµÄ AS Òªº¦×ÖÓÃÓÚ¸øÓÖÃû»ò×ÓÅÌÎÊ·ÖÅÉÒ»¸öÃû³Æ¡£ÓÖÃûÊÇÔʼÃû³ÆµÄÌæ»»Ãû³Æ£¬¶ø×ÓÅÌÎÊÊÇǶÌ×ÔÚÖ÷ÅÌÎÊÖеÄÒ»¸öµ¥¶ÀÅÌÎÊ¡£
ÓÖÃû
ÓÃÓÚ¸ø±í¡¢Áлò±í´ïʽ·ÖÅÉÒ»¸ö²î±ðµÄÃû³Æ¡£
ʹÓÃÓï·¨£ºÔʼÃû³Æ AS ÓÖÃû
ÀýÈ磺
SELECT customer_id AS cust_id, customer_name AS cust_name FROM customers;
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄÅÌÎÊÖУ¬customer_id ±»ÓÖÃûΪ cust_id£¬¶ø customer_name ±»ÓÖÃûΪ cust_name¡£
×ÓÅÌÎÊ
×ÓÅÌÎÊÊÇÒ»¸öǶÌ×ÔÚÖ÷ÅÌÎÊÖеĵ¥¶ÀÅÌÎÊ¡£
ʹÓÃÓï·¨£º(×ÓÅÌÎÊ) AS ÓÖÃû
ÀýÈ磺
SELECT * FROM customers WHERE customer_id IN (SELECT customer_id FROM orders);
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄÅÌÎÊÖУ¬×ÓÅÌÎÊ (SELECT customer_id FROM orders) ²éÕÒÔÚ orders ±íÖб£´æ customer_id µÄ¿Í»§£¬Ð§¹û¼¯±»ÓÖÃûΪ customer_id¡£
ÀûÒæ
ʹÓà AS Òªº¦×Ö¿ÉÒÔ´øÀ´ÒÔÏÂÀûÒ棺
Ìá¸ßÅÌÎʿɶÁÐÔ£º¿ÉÒÔ¸øÄÑÒÔ¼Ç×ŵÄÃû³Æ·ÖÅɸü¾ßÐÎòÐÔµÄÓÖÃû¡£
¼ò»¯ÖØ´óÅÌÎÊ£º¿ÉÒÔͨ¹ý¸ø×ÓÅÌÎÊ·ÖÅÉÓÖÃû£¬Ê¹Ö÷ÅÌÎʸüÈÝÒ×Ã÷È·¡£
±ÜÃâÃû³Æ³åÍ»£ºÈôÊDZí»òÁÐÃû³ÆÏàͬ£¬¿ÉÒÔʹÓÃÓÖÃûÀ´×èÖ¹³åÍ»¡£
ÒÔÉϾÍÊÇsqlÖÐasµÄÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡