【发布时间】:2017-05-04 04:44:04
【问题描述】:
我试图通过将两列值与 where 条件相乘来获得所有行的总和,但得到一些 mysql 错误。在尝试了一些示例后,我实现了我的结果,但我不知道这是否正确:
表格:store_stocks
我只想根据增值税、非增值税和总库存来计算库存数量乘以数量。
我刚刚创建了那个查询:
SELECT sum(qty*sale_price) as total_stock,
(select sum(qty*sale_price) from store_stocks where vat_status = 0 and store_id = 8) as non_vat_stock,
(select sum(qty*sale_price) from store_stocks where vat_status = 1 and store_id = 8) as with_vat_stock
FROM `store_stocks` where store_id = 8 group by store_id
及其显示结果:
谁能告诉我有没有其他方法可以实现这一点,因为我认为查询有点复杂,每次我在子查询中使用 where 时,我还必须在 laravel eloquent 中实现这个查询。
【问题讨论】:
标签: mysql eloquent laravel-5.3