sqlÖÐasµÄÓ÷¨
sql ÖÐ as Òªº¦×ÖÓÃÓÚÖ¸¶¨ÓÖÃû£¬°üÀ¨±í¡¢ÁлòÅÉÉúÖµ£ºÎª±íÖ¸¶¨ÓÖÃû£¬Àû±ã¶à´ÎÒýÓá£ÎªÁÐÖ¸¶¨ÓÖÃû£¬Ã÷È·ÒýÓÃÌض¨ÁС£ÎªÅÉÉúÖµÖ¸¶¨ÓÖÃû£¬ÒýÓÃÅÌËã»ò²Ù×÷Ч¹û¡£
SQL ÖÐ AS Òªº¦×ÖµÄÓ÷¨
ÔÚ SQL Óï¾äÖУ¬AS Òªº¦×ÖÓÃÓÚΪ±í¡¢ÁлòÅÉÉúÖµÖ¸¶¨ÓÖÃû¡£ËüÖ÷ÒªÓÐÒÔϼ¸ÖÖÓ÷¨£º
1. Ϊ±íÖ¸¶¨ÓÖÃû
µ±ÐèÒªÒýÓÃÒ»¸ö±í¶à´Îʱ£¬¿ÉÒÔʹÓà AS ΪËüÖ¸¶¨Ò»¸öÌåÃû£¬È»ºóÔÙʹÓÃÓÖÃûÀ´ÒýÓÃËü¡£ÀýÈ磺
SELECT * FROM customers AS c;
µÇ¼ºó¸´ÖÆ
2. ΪÁÐÖ¸¶¨ÓÖÃû
ͬÑù£¬Ò²¿ÉÒÔʹÓà AS ΪÅÌÎÊЧ¹ûÖеÄÁÐÖ¸¶¨ÓÖÃû¡£ÕâÔÚÅÌÎÊ·µ»Ø¶à¸öÁв¢ÇÒÐèÒªÃ÷È·ÒýÓÃÌض¨ÁÐʱºÜÊÇÓÐÓá£ÀýÈ磺
SELECT customer_id AS ID, customer_name AS Name FROM customers;
µÇ¼ºó¸´ÖÆ
3. ΪÅÉÉúÖµÖ¸¶¨ÓÖÃû
ÔÚ SQL ÖУ¬¿ÉÒÔʹÓÃÔËËã·ûºÍº¯Êý¶ÔÊý¾Ý¾ÙÐÐÅÌËãºÍ²Ù×÷¡£¿ÉÒÔͨ¹ýʹÓà AS ΪÕâЩÅÉÉúÖµÖ¸¶¨ÓÖÃû£¬È»ºóÔÙÔÚÅÌÎÊÖÐÒýÓÃËüÃÇ¡£ÀýÈ磺
SELECT customer_id AS ID, customer_name AS Name, DATEDIFF(NOW(), created_at) AS DaysSinceCreation FROM customers;
µÇ¼ºó¸´ÖÆ
Ó÷¨×¢ÖØÊÂÏ
AS ºóÃæµÄÓÖÃû±ØÐèÊÇΨһµÄ£¬²»¿ÉÓëÅÌÎÊÖÐÆäËûÓÖÃû»ò±íÃû³åÍ»¡£
ÓÖÃû¿ÉÒÔÓÉ×Öĸ¡¢Êý×ÖºÍÏ»®Ïß×é³É£¬µ«²»¿ÉÒÔÊý×Ö¿ªÍ·¡£
ʹÓÃÓÖÃûºó£¬¿ÉÒÔʹÓÃÓÖÃû»òÔʼÃû³ÆÀ´ÒýÓøÃÏî¡£
AS Òªº¦×ÖÊÇ¿ÉÑ¡µÄ£¬µ«ÔÚÌá¸ß´úÂë¿É¶ÁÐԺͿÉά»¤ÐÔ·½ÃæÇ¿ÁÒ½¨ÒéʹÓÃËü¡£
ÒÔÉϾÍÊÇsqlÖÐasµÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡