dongwuxie7976 2017-07-16 18:04
浏览 69
已采纳

使用php查询帐户运行余额

Please assist, how to write php code for the following query:

SELECT transactions_id, trn_date, trn_dt_total, trn_ct_total, trn_description, trn_bank_reference, balance
FROM
(SELECT t.*, @n := IF(@g <> transactions_id, 0, @n) + 
COALESCE(trn_dt_total,0) - COALESCE(trn_ct_total, 0) balance, @g := 
transactions_id
FROM transactions t, (SELECT @n := 0) n, (SELECT @g := 0) g
WHERE trn_building_id = 1 and trn_unit_id = 1 and trn_tenant_id = 1
ORDER BY transactions_id, trn_date)
query

My php page query

$details = $db->query();

When running the query in MySql without the "query" line i get the error:

1248 - Every derived table must have its own alias
  • 写回答

1条回答 默认 最新

  • dousheyan0375 2017-07-16 18:10
    关注

    The error is self explanatory. You should name an alias for the table you created. After the subquery in the parenthesis, you should write as t_name where tname would be your table alias

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

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画