[英]MySQL Query with multiple GROUP BY - How do I make one group a column head and one group a row head in an HTML table?
[英]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
两个表并检查给定交易的帐户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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.