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/oufan 消费统计.sql

50 lines
1.7 KiB

1 year ago
use qingdao_oufan
SELECT * FROM TCompany
SELECT * FROM TBasicType WHERE FKey like '%dep%'
SELECT M.FMemNO AS <EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,M.FName <EFBFBD><EFBFBD><EFBFBD><EFBFBD>,M.FMobilePhone <EFBFBD>ֻ<EFBFBD>,dbo.FNNumToStr(SUM(A.FPayAmt)) AS '<EFBFBD><EFBFBD><EFBFBD>ѽ<EFBFBD><EFBFBD><EFBFBD>'
FROM
(
SELECT A.FMemId,SUM(C.FPayAmt) AS FPayAmt
FROM TConsumeGoods AS B,TConsumeBill AS A,TConsumeGoodsPayment AS C
WHERE B.FDeptId IN (SELECT FId FROM TBasicType WHERE FKey = 'Department' AND FName in('<EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'))
AND A.FBillId = B.FBillId
AND B.FId = C.FDetailId
AND C.FPayTypeId IN(SELECT FId FROM TPayAccount WHERE FIsCashIncome = 1)
AND A.FState = 1
AND A.FWorkDate BETWEEN'2019-08-01' AND '2020-07-30'
AND FMemId IN(SELECT FMemId FROM TMemberCard WHERE FCompId = dbo.FNCompId('001') UNION ALL SELECT FMemId FROM TMemberCourse WHERE FCompID=dbo.FNCompId('001'))
GROUP BY A.FMemId
UNION ALL
SELECT A.FMemId,SUM(C.FPayAmt) AS FPayAmt
FROM TConsumeItem AS B,TConsumeBill AS A,TConsumeItemPayment AS C
WHERE B.FDeptId IN (SELECT FId FROM TBasicType WHERE FKey = 'Department' AND FName in('<EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>' ,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'))
AND A.FBillId = B.FBillId
AND B.FId = C.FDetailId
AND C.FPayTypeId IN(SELECT FId FROM TPayAccount WHERE FIsCashIncome = 1)
AND A.FState = 1
AND A.FWorkDate BETWEEN'2019-08-01' AND '2020-08-31'
GROUP BY A.FMemId
UNION ALL
SELECT A.FMemId,SUM(C.FPayAmt) AS FPayAmt
FROM TMemberSaleBill AS A,TMemberSaleDetailSplit AS C
WHERE C.FDeptId IN (SELECT FId FROM TBasicType WHERE FKey = 'Department' AND FName in('<EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>' ,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'))
AND A.FBillId = C.FBillId
AND C.FPayTypeId IN(SELECT FId FROM TPayAccount WHERE FIsCashIncome = 1)
AND A.FState = 1
AND A.FWorkDate BETWEEN'2020-04-01' AND '2020-09-30'
GROUP BY A.FMemId
) AS A,TMember AS M
WHERE M.FMemId = A.FMemId
GROUP BY A.FMemId,M.FMemNo,M.FName,M.FMobilePhone
ORDER BY SUM(A.FPayAmt) DESC