函数调用为列名

时间:2017-09-19 11:47:59

标签: sql-server

当没有指定时,是否可以让SQL Server Management Studio自动生成列名?例如,基于生成它们的表达式。

例如,拥有查询

会很高兴
SELECT ProductType, AVG(Price)
FROM Products
GROUP BY ProductType

生成类似

的内容
ProductType | AVG(Price)
------------+-----------
Product1    | 42
...         | ...

而不是

ProductType | (No column name)
------------+-----------------
Product1    | 42
...         | ...

目前的情况。

2 个答案:

答案 0 :(得分:0)

SQL Server(Transact-SQL)ALIASES可用于为列或表创建临时名称。

SELECT ProductType, AVG(Price) as AVG
FROM Products
GROUP BY ProductType

https://www.techonthenet.com/sql_server/alias.php

答案 1 :(得分:0)

您也可以在''中命名新列。例如,你可以写:

SELECT ProductType, AVG(Price) as 'AVG(Price)'
FROM Products
GROUP BY ProductType
相关问题