选择SQL语句group by并将两列相加

时间:2016-04-21 14:24:03

标签: sql sql-server

我有一个sql语句,我无法正确地获取结构,当我运行我目前拥有的时它说语法错误。我看的结果看起来像这样: -

Valid XHTML http://www.churchcom.co.uk/test/Capture2.JPG

到目前为止,这是我的查询,但我不认为我在正确的轨道上。

SELECT        Name, ValueofTaught, Amount  
FROM            Activities
WHERE        (Department = @Department)
ORDER BY Name
GROUP BY BurnhamGrade
(SUM ValueofTaught AND Amount
WHERE Departmetn = @Department)

活动的结构表如下: -

Valid XHTML http://www.churchcom.co.uk/test/Capture3.JPG

1 个答案:

答案 0 :(得分:2)

听起来有点像group by两列。我假设Value of Taught列是卷起几个小时的内容:

SELECT        Department, Name, SUM([Value of Taught]) Hours, SUM(Amount) Pay
FROM          Activities
GROUP BY      Department, Name
ORDER BY      Department, Name
WITH ROLLUP