如何获取表格中所选列的总计数。 [英] How do I get the total count over selected columns in my table.
本文介绍了如何获取表格中所选列的总计数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取表格中所选列的总数。
我的表中有45列。我需要将其中的43个总和并计入一个计数器。
我似乎无法使这个sql语句起作用:
SELECT SUM([索引],[ 01 ],[ 02 ],...,[at]) FROM [count];
...是43列的其余部分。
可以你有帮助吗?
解决方案
SUM是一个聚合,而不是一个genaric函数。我不知道你的最终目标,但这些是你的选择:
只需使用加法,即可获得特定culumn值的总和。您将获得与您的选择一样多的行:
SELECT [索引] + [ 01 ] + [ 02 ] + ... + [at] as [SUM] FROM [count];
您可以自己汇总每一列。您将获得一行,包含尽可能多的值,添加的列数:
SELECT SUM( [ index ]),SUM([ 01 ]),SUM([ 02 ]),...,SUM([at]) FROM [count];
当然,你可以将这些结合起来,得到所有的总和:
SELECT SUM([索引] + [ 01 ] + [ 02 ] + ... + [at]) as [SUM] FROM [ count];
尝试 SELECT SUM([index]),sum([01]),sum([02]), sum([03]),sum([04])... FROM [count];
试试
< pre lang =SQL> SELECT
(col1 + col2 + .... + coln) as ROWTOTAL
FROM
TABLENAME
I am trying to get the total count over selected columns in my table.
I have 45 columns in my table. I need 43 of them summed and totaled for a counter.
I can not seem to get this sql statement to work:
SELECT SUM([index],[01],[02],...,[at]) FROM [count];
The "..." are the rest of the 43 columns.
Can you help?
解决方案
SUM is an aggregate, not a genaric function. I don't know get your final goal, but these are your options:
Simply use addition, to get the sum of specific culumn values. You will get as many rows as your selection gives:
SELECT [index]+[01]+[02]+...+[at] as [SUM] FROM [count];
You can summarize each column on it's own. You will get one row, with as many values, as many columns you add:
SELECT SUM([index]), SUM([01]), SUM([02]),...,SUM([at]) FROM [count];
And of course, you can combine these, to get the sum of all:
SELECT SUM([index]+[01]+[02]+...+[at]) as [SUM] FROM [count];
Try SELECT SUM([index]), sum([01]),sum([02]),sum([03]),sum([04])... FROM [count];
try like
SELECT (col1+ col2 + .... +coln) as ROWTOTAL FROM TABLENAME
这篇关于如何获取表格中所选列的总计数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文