I have a member that can pay in three different ways:
How can I design a table t
Store all income in a Payments
table. Each Payment
specifies a payment method from the PaymentMethods
table and is related to an order in the Orders
table.
In the past I stored payment methods in a table, but after some thinking I conclude that an IPaymentMethod
interface with derived classes (eg. class CreditCard : IPaymentMethod
), would be easier to extend and maintain.
PaymentMethods
TableOrders
TableUsers
table)Payments
TableOrders
table)PaymentMethods
table)To determine the total value of payments received for any given Order
, simply sum the Amount the Payments
table, grouped by Order ID
:
SELECT
OrderID,
SUM(Amount) as Saldo
FROM Payments
GROUP BY
Payments.OrderID