php - 如何获取组头结果另一个表 MySQL 查询
问题描述
我有两张桌子
团体
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
推荐阅读
- python - 使用 Pandas 在现有的大型 CSV 文件中插入一列,而不会消耗太多 RAM
- kubernetes - 遥测混频器日志
- cassandra - ScyllaDB - [无效查询] 消息 =“封送错误:毫秒长度超出预期 (6)”
- java - 为我的项目创建像 Slf4j 这样的注释
- terraform - 使用 for_each 创建的资源中带有 for_each 的动态块
- html - 如何使 div 填充绝对底部 div 的剩余空间
- android - 在 LG K20 上从 apk 安装应用程序时出现问题
- r - 将多个图像组合在一起
- r - 如何阻止 renderTable 默认为小数点后 2 位?
- bash - 在 docker compose build 期间运行 git clone 和 rsync bash 脚本