计算 sum() 两个别名命名的列 - 在 sql 中
计算查询中声明的两个临时列名称的 sum() - 在 SQL
stud
表中只有两列 m1,m2
。 Total 和total1 作为临时名称给出。
select
m1, m2,
SUM(m1) + SUM(m2) as Total,
SUM(m1) + SUM(m2) as Total1
from
stud
group by
m1, m2
如何将 grandtotal
计算为 sum(total)+sum(total1)
并将列名称声明为要执行的查询的临时名称。
cte 不支持重复的列名?
如何利用它来支持重复的列名
To calculate sum() of two temp column names declared in query - in SQL
stud
table has only two columns m1,m2
. total and total1 is given as temp name.
select
m1, m2,
SUM(m1) + SUM(m2) as Total,
SUM(m1) + SUM(m2) as Total1
from
stud
group by
m1, m2
How to calculate grandtotal
as sum(total)+sum(total1)
with the column name declared as temp name for the query to execute.
With cte dosn't support duplicate column names?
How to make use of it to support duplicate columnname
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能直接执行此操作 - 您需要使用类似 CTE(通用表表达式)之类的东西 - 像这样:
这适用于 SQL Server 2005 及更高版本(以及支持 CTE 的其他一些数据库系统 - 这是一个 ANSI 标准)。
You can't do it directly - you need to use something like a CTE (Common Table Expression) - like this:
This works in SQL Server 2005 and newer (and also in some other database systems that support CTE's - which is an ANSI standard).
在第一个和第二个字段中,字段数据类型为 nvarchar ,如果字段为整数,则为
表名称。
in this first and second is field datatype is
nvarchar
, and if fields are ininteger
thenis table name.