开发者

total two or more values under one ID in SQL

开发者 https://www.devze.com 2022-12-11 20:45 出处:网络
![alt text][1] [1]: http://C:\\开发者_如何学GoDocuments and Settings\\Administrator\\My Documents\\My Pictures\\Ashampoo Magical Snap 2\\Magical Snap - 2009.11.16 23.07 - 003.jpg

![alt text][1]

[1]: http://C:\开发者_如何学GoDocuments and Settings\Administrator\My Documents\My Pictures\Ashampoo Magical Snap 2\Magical Snap - 2009.11.16 23.07 - 003.jpg

In referring to the picture there are several entries where the same Student ID repeats. Where this happens I'd like to combine the money owed by totaling any multiple entries under one Student ID. What do I need to add to the code below to accomplish this, please? I am using Access 2007 & the code below is the SQL view that is responsible for producing the pictured table. Thnaks, in advance, for the help!!!

SELECT Students.[Student ID], Students.[Last Name], Students.[Dorm Addess], [Number of Hours]*[Price Per Hour] AS [Money Owed]
FROM Students INNER JOIN ([Price List and Job Description] INNER JOIN Visits ON [Price List and Job Description].[Job ID] = Visits.[Job ID]) ON Students.[Student ID] = Visits.[Student ID];


Well, if i understand correcly you need a SUM and GROUP BY to achieve this.

Something like this

SELECT  Students.[Student ID], 
        Students.[Last Name], 
        Students.[Dorm Addess], 
        SUM([Number of Hours]*[Price Per Hour]) AS [Money Owed]
FROM    Students INNER JOIN 
        ([Price List and Job Description] INNER JOIN 
        Visits ON [Price List and Job Description].[Job ID] = Visits.[Job ID]) ON Students.[Student ID] = Visits.[Student ID]
GROUP BY Students.[Student ID], 
        Students.[Last Name], 
        Students.[Dorm Addess]


the intarwebs don't have access to your C:\Documents and Settings\, nobody sees your jpeg

0

精彩评论

暂无评论...
验证码 换一张
取 消