我在mysql数据库中有两个名为“Customers
”和“Committeetables
”的表。他们有以下专栏
表:客户
nd Name FatherName Cell# AdvanceAmount
25 Waseem Asghar 0302 2500
30 Ramzan Khan 0303 3500
35 Rana Ali 0307 2000
表:委员会表
nd Amount RecievingDate DrawDate
25 1500 2-10-15 10-10-15
30 1500 2-10-15 10-10-15
25 1500 3-10-15 10-11-15
30 1500 3-10-15 10-11-15
35 1500 3-10-15 10-11-15
“nd
”表中的列“Customers
”是主键,“CommitteeTables
”表中的列是外键。这意味着“Customers
”表通过“ComitteeTables
”列与“nd
”表相连接。
预期结果表应如下:
nd Name Father Name Cell# Advance Amount Balance
25 Waseem Asghar 0302 25000 3000 22000
30 Ramzan Khan 0303 35000 3000 32000
32 Rana Ali 0307 20000 1500 18500
----------------------------------------------------------------------------
total 80000 7500 72500
我正在使用Laravel 5和HTML,Bootstrap。我需要在Laravel 5中得到这个结果。如果有人帮助我解决我的问题,我将非常感激。
由于
瓦西姆
答案 0 :(得分:0)
这根本不是Laravel的问题。这是一个普遍的SQL问题。
这样的事情:
SELECT nd, Name, FatherName, Cell#, AdvanceAmount as Advance,
(SELECT SUM(Amount) FROM CommitteeTables WHERE CommitteeTables.nd=Custoemr.nd) as Amount, Advance-Balance AS Balance
FROM Customer;
我不完全确定这是正确的,但您可以尝试并修复任何错误。正如波格丹建议你先尝试一下,然后回到这里,遇到任何问题。