asÔÚsqlÖеÄÒâ˼
as ÔÚ sql ÖÐ×÷ΪҪº¦×Ö£¬ÓÃÓÚΪÓÖÃû»òÔÝʱ±í·ÖÅÉÃû³Æ£¬Ìá¸ßÅÌÎʿɶÁÐԺͿÉÃ÷È·ÐÔ¡£ÓÃ;°üÀ¨£ºÎª±í»òÁн¨ÉèÓÖÃû£»ÎªÅÉÉú±í»òÊÓͼ½¨ÉèÔÝʱ±í¡£
AS ÔÚ SQL ÖеļÄÒå
¼ÄÒå
AS ÊÇ SQL ÖеÄÒªº¦×Ö£¬ÓÃÓÚΪÓÖÃû»òÔÝʱ±í·ÖÅÉÒ»¸öÃû³Æ¡£ËüÔÊÐíÎÒÃÇÒÔ²î±ðµÄÃû³ÆÒýÓÃ±í¡¢Áлò±í´ïʽ£¬´Ó¶øÌá¸ßÅÌÎʵĿɶÁÐԺͿÉÃ÷È·ÐÔ¡£
ÓÃ;
AS Ö÷ÒªÓÃÓÚÒÔÏÂÓÃ;£º
Ϊ±í»òÁн¨ÉèÓÖÃû£ºÕâ¿ÉÒÔ¼ò»¯³¤±íÃû»òÁÐÃû£¬»ò½«ÆäÖØÃüÃûΪ¸ü¾ßÐÎòÐÔµÄÃû³Æ¡£ÀýÈ磺
SELECT * FROM users AS u
µÇ¼ºó¸´ÖÆ
ΪÅÉÉú±í»òÊÓͼ½¨ÉèÔÝʱ±í£º½«ÅÌÎÊЧ¹û·ÖÅɸøÔÝʱ±íʱ£¬¿ÉÒÔʹÓà AS Ϊ¸Ã±íÃüÃû¡£ÀýÈ磺
SELECT * FROM users WHERE age > 30 AS old_users
µÇ¼ºó¸´ÖÆ
Óï·¨
ʹÓà AS µÄÓï·¨ÈçÏ£º
[¹¤Ç©×Ö³Æ] AS [ÓÖÃû]
µÇ¼ºó¸´ÖÆ
ÆäÖУº
[¹¤Ç©×Ö³Æ] ÊÇҪΪÆ佨ÉèÓÖÃûµÄ±í¡¢Áлò±í´ïʽ¡£
[ÓÖÃû] ÊÇÒª·ÖÅɸø¹¤¾ßµÄÃû³Æ¡£
ʾÀý
ÒÔÏÂÊÇһЩʹÓà AS µÄʾÀý£º
-- Ϊ users ±í½¨ÉèÓÖÃû u SELECT * FROM users AS u -- ΪÅÉÉú±í½¨ÉèÔÝʱ±í old_users SELECT * FROM users WHERE age > 30 AS old_users -- ΪÅÌËãÁÐ age_group ½¨ÉèÓÖÃû group SELECT *, CASE WHEN age
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇasÔÚsqlÖеÄÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡