嵌套 MySQL 查询?
我有这个运行良好的 MySQL 语句:
SELECT claim_items.item_id, claim_items.quantity*items_rate.rate as per_item
FROM claim_items, items_rate
WHERE claim_items.claim_id = 1 AND claim_items.item_id = items_rate.items_id
但是我想要做的是获取 MySQL 语句中生成的 per_item 字段的总和。是否可以通过嵌套语句来做到这一点?我知道我可以创建一个视图然后执行它,但更喜欢在一个语句中执行它。
感谢您的帮助,非常感谢!
I have this MySQL statement which works fine:
SELECT claim_items.item_id, claim_items.quantity*items_rate.rate as per_item
FROM claim_items, items_rate
WHERE claim_items.claim_id = 1 AND claim_items.item_id = items_rate.items_id
However what I want to do is to get the sum of the per_item field generated in the MySQL statement. Is it possible to do a nested statement to do that? I know I could create a view and then do it, but would prefer to do it in one statement.
Thanks for your help, much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望这会有所帮助。
Hope this should help.
如果您只想要所有行的总和,您可以这样做(使用显式连接以获得更好的可读性):
If you just want the sum over all rows you can do it like that (using explicit joins for better readability):