2015-06-23 147 views
0

我了解汇总“硬”数字的用法。但是我有一对夫妇需要小计,并且无法弄清楚。我的查询是:汇总字段的小计

SELECT entryno 
,Section 
, Grade, replace(replace('<feet>'' <inches>', '<feet>', Mylength/12), '<inches>', Mylength % 12) as Mylength 
, Pcs 
, MyNote 
, MyReason 
, savedatetime 
, secwgt 
,(select str(sum(secwgt*pcs*MyLength),12,3) from NYS2RandomReport t2 where (t2.entryno = t.entryno)) as lbs 
,(select str(sum(secwgt*pcs*MyLength/2000),12,3) from NYS2RandomReport t2 where (t2.entryno = t.entryno)) as tons 
From NYS2RandomReport t 
ORDER BY section, grade, mylength 

和回报是:

4 W14X120 A588-B 10' 0 7   2015-04-15 12:00:00.000 8.5000  7140.000   3.570 
5 W14X120 A588-B 10' 1 6   2015-04-15 12:00:00.000 8.5000  6171.000   3.086 
6 W14X120 A588-B 10' 2 3   2015-04-15 12:00:00.000 8.5000  3111.000   1.556 
3 W14X120 A992 10' 4 8   2015-04-15 12:00:00.000 8.5000  8432.000   4.216 
1 W14X89 A992 20' 0 10 Not for sale Cracked 2015-04-15 12:00:00.000 8.1666  19599.840   9.800 
2 W14X89 A992 21' 5 4 Not for sale Cracked 2015-04-15 12:00:00.000 8.1666  8395.265   4.198 

的最后两列是磅吨。我需要按部分栏目分组的那两列的小计。

这让我感到莫名其妙。谢谢。

+0

你的意思是说如果不把它们当作字符串,你会知道该怎么办? –

+0

是的,卷起柱子(pcs)不会有问题,但我无法弄清楚如何处理其他2个领域(磅和吨)。他们是我唯一需要小计的人。 – Obfuscated

+0

然后在转换中将它们卷起来。确保将它们铸成字符串是最后一步。 –

回答

1

只要确保首先执行任何卷起,然后将str()转换包装在它们周围。

(select str(sum(secwgtpcsMyLength),12,3) from NYS2RandomReport t2 where (t2.section = t.section) and (t2.grade=t.grade)) as SectionGradelbs