我有以下输出以下图像的 mysql 查询:
select
v.invoicenumber,
v.invoicedate,
v.haulier,
v.transporttype,
count(v.loadnumber) as totalloads,
sum(v.cost) as totalcost,
concat(SUM(if(invoiceapproved = 'yes', 1, 0)),' / ',count(v.loadnumber)) AS count, SUM(if(invoiceapproved = 'yes', 1, 0)) as approved
from v2loads v
where v.invoiced='yes'
group by invoicenumber
此查询执行 100%。
我想要做的是过滤掉计数为 100% 的任何行/数据。在示例输出中,我想过滤掉发票 16,因为它是 2/2 和 100%。所以在哪里
count(v.loadnumber) <> SUM(if(invoiceapproved = 'yes', 1, 0))
如果我将此逻辑添加到 where 子句中,则会因错误无效使用组函数而失败。所以下面的代码不起作用:
select v.invoicenumber,
v.invoicedate,
v.haulier,
v.transporttype,
count(v.loadnumber) as totalloads,
sum(v.cost) as totalcost,
concat(SUM(if(invoiceapproved = 'yes', 1, 0)),' / ',count(v.loadnumber)) AS count,
SUM(if(invoiceapproved = 'yes', 1, 0)) as approved
from v2loads v
where v.invoiced='yes' and
(count(v.loadnumber))<>(SUM(if(invoiceapproved = 'yes', 1, 0)))
group by invoicenumber
我收到以下错误:
错误是
#1111
- 组功能的使用无效。
任何建议一如既往地受到赞赏。