PHP Mysql显示来自两个表的必要记录

时间:2016-09-21 06:47:26

标签: php mysql

我有两个表,brp_consume_logbrp_transfer_log,我在表格中加入了查询:

SELECT * 
FROM brp_consume_log a
JOIN brp_transfer_log b ON b.acct_id = a.acct_id
WHERE a.acct_id ='1657'

结果输出为:

join tables

我想以下面的格式显示结果:

enter image description here

有可能吗?

更新 我已经能够使用下面的查询输出我想要的结果:

SELECT 
    datetime, 
    remark, 
    intake, 
    consume 
FROM
  (
    SELECT datetime, remark, points_intake intake, NULL consume, 1 ord
    FROM brp_transfer_log
    WHERE acct_id = '1657'
    UNION ALL

    SELECT datetime, remark, NULL, point_consume, 2
    FROM brp_consume_log
    WHERE acct_id = '1657'
  ) q
ORDER BY datetime DESC, ord

enter image description here

顺便说一下,如何为balance points添加另一个字段并从上一个余额点进行必要的减法或加法?

请指教。谢谢!

0 个答案:

没有答案