简体   繁体   English

使用两列计算总金额,百分比是多少?

[英]Calculating total amount using two columns, with a percentage?

I have built a table that includes various items, item id's and prices etc - I also have a list of stored customers on my database and the items that they bought. 我已经建立了一个包含各种项目,项目ID和价格等的表格 - 我还有一个在我的数据库中存储的客户列表以及他们购买的项目。

I would like to be able to calculate my total VAT (16%) for these items, only the ones sold (not unsold items). 我希望能够计算这些物品的总增值税(16%),只计算出售的物品(不是未售出物品)。

I tried this code: 我试过这段代码:

SELECT sum(items.price*sales.amount) as 'Total Sold', sum((items.price*sales.amount)*0.16) AS 'Estimated Total Vat Amount'
FROM sales

But the result that followed was an 'unknown column' although it does exist. 但随后的结果是“未知专栏”,尽管确实存在。 On looking online is encourages me to use an 'inner join' but if possible I would prefer to use something else.. 在网上看是鼓励我使用'内部联接',但如果可能的话我宁愿使用别的东西..

Is that possible? 那可能吗? if so, what could I use to get my result? 如果是这样,我可以用什么来获得我的结果?

Thanks. 谢谢。

You need to join items table. 您需要加入项目表。

SELECT 
    sum(items.price*sales.amount) as 'Total Sold'
   ,sum((items.price*sales.amount)*0.16) AS 'Estimated Total Vat Amount'
FROM 
    sales
INNER JOIN
    items
ON
    sales.item_id=items.id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM