duanjiancong4860 2019-02-02 01:39
浏览 18
已采纳

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

I have Two Table

group

gid| account         | head
---------------------------------
1  | first cash      | CashinHand
2  | second cash     | CashinHand
3  | third  cash     | CashinHand
4  | office expense  | Expense

trans

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

// I want Get Report All Cash . It depend Group table Head CashinHand like this

tid| particular      | amount
------------------------------
1  | first cash      | 100
3  | second cash     | 130
4  | third  cash     | 50
5  | first cash      | 110
  • 写回答

1条回答 默认 最新

  • dshp9580656 2019-02-02 01:42
    关注

    You just need to JOIN your two tables and check that the account head for a given transaction is CashInHand:

    SELECT t.*
    FROM trans t
    JOIN `group` g ON g.account = t.particular
    WHERE g.head = 'CashInHand'
    

    Output:

    tid     particular      amount
    1       first cash      100
    3       second cash     130
    4       third cash      50
    5       first cash      110
    

    Demo on SQLFiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拓扑学,凸集,紧集。。
  • ¥15 如何扩大AIS数据容量
  • ¥15 单纯型python实现编译报错
  • ¥15 c++2013读写oracle
  • ¥15 c++ gmssl sm2验签demo
  • ¥15 关于模的完全剩余系(关键词-数学方法)
  • ¥15 有没有人懂这个博图程序怎么写,还要跟SFB连接,真的不会,求帮助
  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音