mysqlÖÐasµÄÓ÷¨
mysql ÖÐ as Òªº¦×ÖÓÃÓÚ½¨ÉèÅÌÎÊÖбíµÄÓÖÃû»òÁеÄÔÝʱÃû³Æ£¬ÒÔ±ãÓøüÒ×Ã÷È·µÄÃû³ÆÌæ»»ÔʼÃû³Æ¡£Ëü¿ÉÒÔÌá¸ßÅÌÎʿɶÁÐÔ¡¢Ïû³ýÆçÒå²¢½¨ÉèÔÝʱÃû³Æ¡£Ê¹ÓÃÓ﷨Ϊ£ºselect … as alias_name from … where …¡£
MySQL ÖÐ AS µÄÓ÷¨
¼ò½é
AS Òªº¦×ÖÔÚ MySQL ÖÐÓÃÓÚ¸øÅÌÎÊÖеÄÓÖÃû»òÔÝʱÃû³Æ¡£ËüÔÊÐíÄúÓøüÒ×ÓÚÃ÷È·»òʹÓõÄÃû³ÆÌæ»»Ôʼ±íÃû»òÁÐÃû¡£
ʹÓó¡¾°
AS Òªº¦×ÖÔÚÒÔϳ¡¾°ÖкÜÊÇÓÐÓãº
ʹÅÌÎʸü¾ß¿É¶ÁÐÔ£ºµ±±í»òÁÐÃûºÜ³¤»òÄÑÒÔÓ°Ïóʱ£¬Ê¹Óà AS ¿ÉÒÔ½«ÆäÌ滻Ϊ¸ü¼ò¶Ì¡¢¸üÓѺõÄÃû³Æ¡£
Ïû³ýÆçÒ壺µ±ÅÌÎÊÖÐÉæ¼°¶à¸ö¾ßÓÐÏàͬÃû³ÆµÄ±í»òÁÐʱ£¬AS ¿ÉÒÔ×ÊÖúÇø·ÖËüÃÇ¡£
½¨ÉèÔÝʱÃû³Æ£ºAS ¿ÉÒÔ½¨ÉèÔÝʱÃû³Æ£¬ÓÃÓÚ´æ´¢ÅÌËãЧ¹û»ò´Ó×ÓÅÌÎÊ·µ»ØµÄÖµ¡£
ʹÓÃÓï·¨
AS Òªº¦×ÖµÄÓï·¨ÈçÏ£º
SELECT ... AS alias_name FROM ... WHERE ...
µÇ¼ºó¸´ÖÆ
ÆäÖУº
alias_name£ºÒª¸¶Óë±íÃû»òÁÐÃûµÄÓÖÃû¡£
…£ºÒªÌæ»»µÄÔʼ±íÃû»òÁÐÃû¡£
ʾÀý
½«±íÃû “customers” Ì滻Ϊ “c”£º
SELECT * FROM customers AS c;
µÇ¼ºó¸´ÖÆ
½«ÁÐÃû “last_name” Ì滻Ϊ “lname”£º
SELECT first_name, last_name AS lname FROM employees;
µÇ¼ºó¸´ÖÆ
½¨ÉèÒ»¸öÔÝʱÃû³Æ “total_sales” À´´æ´¢ÅÌËãЧ¹û£º
SELECT SUM(sales) AS total_sales FROM orders;
µÇ¼ºó¸´ÖÆ
×¢ÖØ
AS Òªº¦×ÖÊÇ¿ÉÑ¡µÄ¡£ÈôÊÇÄú²»Ö¸¶¨ÓÖÃû£¬MySQL ½«×Ô¶¯ÌìÉúÒ»¸öÌåÃû£¬Í¨³£Îª “t1″¡¢”t2” µÈ¡£
ÓÖÃûÖ»ÄÜÔÚÅÌÎÊÖÐʹÓá£ËüÃDz»»áÓÀÊÀ¸ü¸Ä±í»òÁеÄÃû³Æ¡£
ÓÖÃû²»¿ÉÓë±í»òÁеÄÔʼÃû³ÆÏàͬ¡£
ÒÔÉϾÍÊÇmysqlÖÐasµÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡