2009-11-17 71 views
0

[替代文本] [1]下一個ID共有兩個或多個值在SQL

[1]:http://C:\的Documents and Settings \ Administrator的\ My Documents \我的圖片\ Ashampoo的魔法快2 \妙用快照 - 2009.11.16 23.07 - 003.jpg

在參考圖片時,有幾個條目在相同的學生ID重複。如果發生這種情況,我希望通過在一個學生ID下總計多個條目來合併欠款。我需要添加下面的代碼才能完成此操作? 我正在使用Access 2007 &下面的代碼是負責生成有圖表的SQL視圖。 Thnaks,提前,尋求幫助!

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]; 
+0

我建議你擺脫在字段名和表名的空間,你以後會感謝自己。 – Fionnuala 2009-11-17 11:26:59

+0

謝謝,這是通過訪問產生的,但是pt被採用! – DJF 2009-11-17 11:44:09

+0

呃,那圖形不會顯示,除非你把它上傳到某個公共網站。 – 2009-11-18 00:18:15

回答

1

的intarwebs沒有訪問到C:\ Documents和Settings \,沒有人看到你的JPEG

+0

謝謝....我想出了和正在編輯,但有人回覆,所以我們會看到.... – DJF 2009-11-17 11:34:14

2

好吧,如果我正確地將瞭解你需要一個SUM和GROUP BY實現這一目標。

像這樣的事情

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] 
+0

,讓我排序.....謝謝! – DJF 2009-11-17 11:44:42

相關問題