SELECT transactions_id, trn_date, trn_dt_total, trn_ct_total, trn_description, trn_bank_reference, balance
FROM
(SELECT t.*, @n := IF(@g <> transactions_id, 0, @n) +
COALESCE(trn_dt_total,0) - COALESCE(trn_ct_total, 0) balance, @g :=
transactions_id
FROM transactions t, (SELECT @n := 0) n, (SELECT @g := 0) g
WHERE trn_building_id = 1 and trn_unit_id = 1 and trn_tenant_id = 1
ORDER BY transactions_id, trn_date)
query
$details = $db->query();
在没有“query”行的MySql中运行查询时,我得到了一个错误:
1248 - Every derived table must have its own alias