这是我试图解决的问题......我有三张这样的桌子:
Practice
* PracticeID
* PracticeName
Group
* GroupID
* Sales
* Salaries
* Overheads
Values
* PracticeID
* GroupID
* Income
* Expense
我想要做的是准备一个视图,通过Group表中的组名来总结Value中的收入和支出。我可以得到一行一行的摘要,但我有关于如何在我目前的代码中包含group子句的问题,如下所示:
SELECT Practice.PracticeName, Group.Groupname, Values.Income, Values.Expenses
FROM values INNER JOIN
Practice ON values.PracticeID = Practice.PracticeID INNER JOIN
Group ON Values.NominalGroupID = Group.GroupID
答案 0 :(得分:0)
试试这个:
SELECT Practice.PracticeName, Group.Groupname, SUM(Values.Income) as SumIncome, SUM(Values.Expenses ) as SumExpences
FROM values INNER JOIN
Practice ON values.PracticeID = Practice.PracticeID INNER JOIN
Group ON Values.NominalGroupID = Group.GroupID
Group By Group.Groupname
答案 1 :(得分:0)
您的表格定义并未真正包含您在示例中使用的所有列,因此我不确定您是否正在查找的内容:
SELECT Group.Groupname
,SUM(Values.Income) as Income
,SUM(Values.Expenses ) as Expenses
FROM Group
INNER JOIN Value ON Values.GroupID = Group.GroupID
Group By Group.Groupname