SQL,select的字段如何取别名

SQL如何取别名

 

access 多表查询有重复的字段,而且要前台绑定,怎么办?access用 列表+空格+别名可不行!

要这样:
SELECT product.id as productId,product.name,product.price,car.amount,car.amount*product.price as totalprice from product,car,orderlist where  orderlist.memberid=11 and orderlist.carId=car.Id and car.productId=product.id

 

其实,select列的时候取别名有三种方法,这三种方法并不是所有数据库都适用。

方法一、直接在字段名称后面加上别名,中间以空格隔开。

方法二、以as关键字指定字段别名,as在select的字段和别名之间。

方法三、对于SQL Server 还提供了另外一种方法,之间用“=”号指定。“=”号放在select的字段和别名之间。

例子:

 

SQL Server Oracle

select Emp_Id as EmpId

, Emp_Name "Employee Name"

, Extemsion=Ext

, SUBSTRING(Emp_Id,1.2) "到职位年度"

from Employee

where Dept_Id='I200'

select Emp_Id as EmpId

, Emp_Name "Employee Name"

, Extemsion Ext

, SUBSTR(Emp_Id,1.2) "到职位年度"

from Employee

where Dept_Id='I200'

 

posted @ 2011-10-20 19:41  windwos7  阅读(54342)  评论(0编辑  收藏  举报
点击留言