我有两张 table
群组
gid| account | head
---------------------------------
1 | first cash | CashinHand
2 | second cash | CashinHand
3 | third cash | CashinHand
4 | office expense | Expense
反式
tid| particular | amount
------------------------------
1 | first cash | 100
2 | office expense | 300
3 | second cash | 130
4 | third cash | 50
5 | first cash | 110
6 | office expense | 750
//我想要报告所有现金。取决于组表头CashinHand
像这样
tid| particular | amount
------------------------------
1 | first cash | 100
3 | second cash | 130
4 | third cash | 50
5 | first cash | 110
最佳答案
您只需JOIN
您的两个表并检查给定交易的帐户head
是否为CashInHand
:
SELECT t.*
FROM trans t
JOIN `group` g ON g.account = t.particular
WHERE g.head = 'CashInHand'
输出:
tid particular amount
1 first cash 100
3 second cash 130
4 third cash 50
5 first cash 110
关于php - 如何获取另一个表 MySQL 查询的组头结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54489215/