私はあなたがメンバーレベルで可変契約金額を必要と考えています。例えば、私がサインアップしてデザインを手伝ってくれた場合、あなたが私に請求する金額は会員レベルで購読日に置いておく必要があります。 。サブスクリプションが切れようとしている(スライディングまたはスタティックのいずれか)と、新しいレートになるベースレートが課金されるはずです。私が申し込んだとき、現在までに支払っていた金額、負担する金額(按分した金額かスライド金額)を知っているので、この時点では数学は非常に簡単です。非常に近い
Member
MemberId
Name
Address
Etc...
Product
ProductId
Name
Description
Price
Payment
PaymentId
SubscriptionId
Amount
DatePaid
Subscription
SubscriptionId
MemberId
ProductId
Price
StartDate
EndDate (if needed)
テストされていないクエリが、::
*-- how much do I owe?*
select m.Name, sum(s.Price) - sum(p.Amount) as Owes
from Member m
join Subscription s on m.MemberId = s.MemberId
join Payment p on s.SubscriptionId = p.SubscriptionId
where m.MemberId = 1
*-- how long have I been a member*
select datediff('year', min(StartDate), getdate()) as yrs,
datediff('month', min(StartDate), getdate()) as mths,
datediff('day', min(StartDate), getdate()) as dys
from Subscription
where MemberId = 1
*-- when does my subscription expire*
select max(EndDate) as ExpirationDate
from Subscription
where MemberId = 1
*-- list all payments by product*
select m.Name as MemberName,
pr.Name as ProductName,
pr.Price as ProductPrice,
s.Price as SubscriptionPrice,
p.Amount as AmountPaid
p.PaidDate,
from Member m
join Subscription s on m.MemberId = s.MemberId
join Payment p on s.SubscriptionId = p.SubscriptionId
join Product pr on s.ProductId = pr.ProductId
where MemberId = 1
サンプルスキーマでdatabaseanswers.comを試してみましたか? –
すばらしいサイト!私は今までそれを聞いたことがない。 – James