各位大大好
請問如何在SELECT出多筆資料後,最後一列顯示資料筆數與數量加總?謝謝
AAA 123 100
BBB 456 100
CCC 789 100
筆數:3 總數量300
SQL如下
CREATE TABLE #temp1(
A VARCHAR(20),
B VARCHAR(20),
Prize int
)
INSERT INTO #temp1
(A,B,Prize)
VALUES
('AAA','123',100),
('BBB','456',100),
('CCC','789',100)
select A,B,Prize from #temp1
UNION ALL
select CAST(COUNT(A) as varchar(10)),'',CAST(SUM(prize) as varchar(10)) from #temp1
drop table #temp1
SELECT * FROM "表格名";
SELECT COUNT("欄位名"),SUM ("欄位名") FROM "表格名";