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