你能帮我解决我的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绅士。 –