SQL Alias
表的 SQL Alias 语法
SELECT COLUMN_NAME(S) FROM TABLE_NAME AS ALIAS_NAME
列的 SQL Alias 语法
SELECT COLUMN_NAME AS ALIAS_NAME FROM TABLE_NAME
CAR表:
VIN | BRAND | MODEL | PRICE | PRODUCTION_YEAR |
---|---|---|---|---|
LJCPCBLCX14500264 | Ford | Focus | 8000 | 2005 |
WPOZZZ79ZTS372128 | Ford | Fusion | 10000 | 2008 |
JF1BR93D7BG498281 | Toyota | Avensis | 10000 | 1999 |
KLATF08Y1VB363636 | Volkswagen | Golf | 3000 | 1992 |
1M8GDM9AXKP042788 | Volkswagen | Golf | 10000 | 2010 |
1HGCM82633A004352 | Volkswagen | Jetta | 6000 | 2003 |
1G1YZ23J9P5800003 | Fiat | Punto | 6000 | 1999 |
GS723HDSAK2399002 | Opel | Corsa | 89000.00 | 2007 |
LP859CCSRH5555963 | Toyota | Avensis | 12000.00 | 2009 |
LP859CCSRH5555962 | Opel | Punto | 13000.00 | 2012 |
BICYCLE表:
IDENTIFIER | ALIAS | BRAND | PRICE | PRODUCTION_YEAR |
---|---|---|---|---|
AKSLNF355 | 小红单车 | Mobike | 1.00 | 2015 |
BVSLNF385 | 小黄单车 | Ofo | 1.00 | 2015 |
– Alias 实例: 使用表名称别名
我们有两张表CAR和BICYCLE,分别指定别名C和B,
我们列出BRAND为’Mobike’和’Ford’的数据
SELECT CAR.VIN,BICYCLE.IDENTIFIER,CAR.MODEL,BICYCLE.ALIAS,BICYCLE.BRAND,BICYCLE.PRODUCTION_YEAR FROM CAR,BICYCLE WHERE CAR.BRAND='Ford' AND BICYCLE.BRAND='Mobike';
使用别名:
SELECT C.VIN,B.IDENTIFIER,C.MODEL,B.ALIAS,B.BRAND,B.PRODUCTION_YEAR FROM CAR AS C,BICYCLE AS B WHERE C.BRAND='Ford' AND B.BRAND='Mobike';
PS:在使用别名的时候有的不支持AS
SELECT C.VIN,B.IDENTIFIER,C.MODEL,B.ALIAS,B.BRAND,B.PRODUCTION_YEAR FROM CAR C,BICYCLE B WHERE C.BRAND='Ford' AND B.BRAND='Mobike';
结果:
VIN | IDENTIFIER | MODEL | ALIAS | BRAND | PRICE | PRODUCTION_YEAR |
---|---|---|---|---|---|---|
LJCPCBLCX14500264 | AKSLNF355 | Focus | 小红单车 | Mobike | 1.00 | 2015 |
WPOZZZ79ZTS372128 | AKSLNF355 | Fusion | 小黄单车 | Ofo | 1.00 | 2015 |