ASP网页上显示了明细数据,想在最后一行后面加一行汇总行
ASP网页上显示了明细数据,想在最后一行后面加一行汇总行,请问这个怎样实现,要先在数据库里面汇总起来吗?这样太复杂了吧...
ASP网页上显示了明细数据,想在最后一行后面加一行汇总行,请问这个怎样实现,要先在数据库里面汇总起来吗?这样太复杂了吧
展开
展开全部
1、创建表和演示数据
CREATE TABLE #test (
Name VARCHAR(10),
[procedure] CHAR(1),
model VARCHAR(5),
quantity INT
);
INSERT INTO #test
SELECT 'A', '1', 'φ50', 500 UNION ALL
SELECT 'A', '1', 'φ50', 600 UNION ALL
SELECT 'A', '1', 'φ100', 500 UNION ALL
SELECT 'A', '2', 'φ50', 700 UNION ALL
SELECT 'A', '2', 'φ100', 200 UNION ALL
SELECT 'B', '1', 'φ50', 1000;
2、演示汇总列的使用方法
SELECT
CASE
WHEN GROUPING(Name) = 1 THEN '总计'
WHEN GROUPING(Name) = 0 AND GROUPING([procedure]) = 1 THEN Name + '合计'
WHEN GROUPING(Name) = 0 AND GROUPING([procedure]) = 0 AND GROUPING([model]) = 1 THEN Name + '的' + [procedure] + '小计'
ELSE
Name
END AS Name,
CASE
WHEN GROUPING([model]) = 1 THEN ''
ELSE
[procedure]
END AS [procedure],
ISNULL(model, '') AS model,
SUM(quantity) AS quantity
FROM
#test
group by
Name,
[procedure],
model
with
rollup;
3、结果显示
SQL Server 2005 下测试通过.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询