0
我想创建一个查询来计算应付金额上的情况下,分期付款可为特定paymentSchedule ID进行如何计算这笔付款的到期金额?
我有一个表的支付时间表,因为这:
CREATE TABLE IF NOT EXISTS paymentSchedule (
id int(11) NOT NULL AUTO_INCREMENT,
concept varchar(32) COLLATE utf8_spanish_ci NOT NULL,
student_id int(11) NOT NULL,
dueDate date NOT NULL,
amount decimal(10,2) NOT NULL,
PRIMARY KEY (id)
)
而且我有一个支付交易表这样,wherepaymentSchedule_id表示上面的表:
CREATE TABLE IF NOT EXISTS ledger (
id int(11) NOT NULL AUTO_INCREMENT,
paymentDate date NOT NULL,
amount decimal(10,2) NOT NULL,
paymentSchedule_id int(11) NOT NULL,
PRIMARY KEY (id)
)
我试图到减法喜欢这里: How to substract from the resut of two selects in mysql
但这只有在分类账中存在与相应的paymentSchedule id字段时才有效。 什么是正确的做法?
另一方面,这是存储付款时间表和交易的正确方法吗?
我使用'LEFT JOIN'在您以前的帖子上更新了我的回答。 http://stackoverflow.com/questions/9155230/how-to-substract-from-the-resut-of-two-selects-in-mysql – 2012-02-06 04:29:45