繁体   English   中英

如何获取组头结果另一个表MySQL查询

[英]How to Get Group Head Result another Table MySQL Query

我有两张桌子

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两个表并检查给定交易的帐户headCashInHand

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

关于SQLFiddle的演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM