你能幫我解決我的SQL Query問題嗎?合併重複記錄並更新其表
我想合併/(必要時總和)customer
的所有數據與重複的客戶mame。
在我的項目,我已經找到了所有已使用此代碼複製客戶:
select Firstname, Lastname, count(1) as RepeatedCount
from customer
group by FirstName, LastName
having count(1) > 1
如何更新Customer
表只有1客戶記錄並獲得totalsales
和totavisits
的總和只有一個記錄。
的樣本數據:
FirstName LastName TotalSales TotalVisits
---------- ---------- -------------- -----------
Michelle Go 0.00 0
Michelle Go 6975.00 1
Michelle Go 1195.00 1
Michelle Go 9145.00 3
Michelle Go 57785.00 5
Michelle Go 5845.00 1
Michelle Go 0.00 0
Michelle Go 0.00 0
預期輸出:
FirstName LastName TotalSales TolalVisits
---------- ---------- -------------- -----------
Michelle Go 80945.00 11
MySQL或SQL的服務器? –
SQL Server紳士。 –