You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sql-tools/合并相同手机会员.sql

93 lines
2.1 KiB

1 year ago
use jinan_babi
SELECT * FROM TImpMember
DROP TABLE TMember_Unique
SELECT MIN(FCreateDate) AS FCreateDate, FName,FMobilePhone,SUM(1) AS FCount,CAST(0 AS BIGINT) AS FNewMemId
INTO TMember_Unique
FROM TMember
WHERE FMobilePhone > ''
AND FMemId NOT IN(SELECT FMemId FROM TConsumeBill)
AND FMemId NOT IN(SELECT FMemId FROM TMemberSaleBill)
GROUP BY FName,FMobilePhone
HAVING(SUM(1) > 1)
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>memId
UPDATE A
SET A.FNewMemId = B.FMemId
FROM TMember_Unique AS A
INNER JOIN TMember AS B ON B.FMobilePhone = A.FMobilePhone AND A.FName = B.FName
WHERE B.FCreateDate = A.FCreateDate
AND B.FMemId NOT IN(SELECT FMemId FROM TConsumeBill)
AND B.FMemId NOT IN(SELECT FMemId FROM TMemberSaleBill)
--<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>Ա
SELECT A.FMemId,A.FMobilePhone,A.FName,B.FNewMemId
INTO TMember_Update
FROM TMember AS A,TMember_Unique AS B
WHERE B.FMobilePhone = A.FMobilePhone AND A.FName = B.FName
ORDER BY B.FMobilePhone
--<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCard AS A,TMember_Update AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId != B.FNewMemId
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCourse AS A,TMember_Update AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId != B.FNewMemId
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCourseLog AS A,TMember_Update AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId != B.FNewMemId
SELECT * FROM TMember WHERE FName = '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
SELECT * FROM TMemberCourse WHERE FMemId = 6376533
USE JINAN_BABI
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCardAccount AS A,TMember_Update AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId != B.FNewMemId
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberCardAcctHist AS A,TMember_Update AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId != B.FNewMemId
UPDATE A
SET A.FMemId = B.FNewMemId
FROM TMemberTransHist AS A,TMember_Update AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId != B.FNewMemId
UPDATE A
SET A.FMemNO = FMemNo + '<EFBFBD><EFBFBD>ͬɾ<EFBFBD><EFBFBD>',
A.FDeleted = 1
FROM TMember AS A,TMember_Update AS B
WHERE A.FMemId = B.FMemId
AND A.FMemId != B.FNewMemId
SELECT * FROM TMember_Update
SELECT * FROM TConsumeBill ORDER BY FBillTime DESC