MySql嵌套选择和百分比

时间:2019-04-14 10:07:47

标签: mysql nested percentage

我有这个代码。当两个选择分别工作时,它可以工作,但是当我尝试将其组合起来并以百分比形式计算产品销售量的增长时,它就不再起作用。

use bookstore;
select (select coalesce(year(c.transdate)), coalesce(month(c.transdate)), sum(c.quantity * b.cost * b.vat) where year(c.transdate) = 2016 and month(c.transdate) = 3)   As First_month,
(select (coalesce(year(c.transdate)), sum(c.quantity * b.cost * b.vat) where year(c.transdate) = 2016) As Total_Sold, 
((First_month - total sold)/ First_mont) * 100)) as Increase
from cust_order as c
join book as b
on c.isbn = b.isbn;

我希望第一个月的销售量,总销售额以及百分比差异都能得到三列。

非常感谢您的帮助。

0 个答案:

没有答案