sql-server – 如何为SUM列指定名称?

前端之家收集整理的这篇文章主要介绍了sql-server – 如何为SUM列指定名称?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何为SUM列分配列名?

select OwnerUserId,SUM(Postscore)
INTO Experts
from ...

我收到此错误

An object or column name is missing or
empty. For SELECT INTO statements,
verify each column has a name. For
other statements,look for empty alias
names. Aliases defined as “” or [] are
not allowed. Change the alias to a
valid name.

我想因为包含SUM结果的列没有名称.

解决方法

首先,没有sql-Server 2003.只有2000,2005,2008(以及2008R2,2012和最新的2014).

至于名称 – 称为别名 – 您可以使用AS.这是标准的sql语法:

SELECT OwnerUserId,SUM(Postscore) AS PostscoreSum
INTO Experts 
FROM ...

但AS是可选的,因此您也可以在没有它的情况下为列添加别名:

SELECT OwnerUserId,SUM(Postscore)  PostscoreSum
INTO Experts 
FROM ...

您还可以使用(专有的,仅在sql-Server中)alias = column语法:

SELECT OwnerUserId,PostscoreSum = SUM(Postscore)  
INTO Experts 
FROM ...
原文链接:https://www.f2er.com/mssql/83922.html

猜你在找的MsSQL相关文章