[英]How can i remove results with that give me a zero sum, not using a subquery?
I can't have sums that give me a zero value. 我的总和不能为零。 So i used a subquery to achive it.
所以我用一个子查询来实现它。 Problem is that sub-queries are not fast.
问题在于子查询不是很快。 How would you make it to be more efficient?
您将如何提高效率?
select * from (
SELECT a,
b,
c,
sum(d) as ftd
FROM items f
WHERE f.category = 'ANY' AND
f.version = 'V2018' AND
f.month = '01' AND
f.year = '2017'
Group by f.a,
f.b,
f.c
ORDER BY f.a,
f.b,
f.c
)where ftd!=0;
Use HAVING
使用
HAVING
SELECT a,
b,
c,
sum(d) as ftd
FROM items f
WHERE f.category = 'ANY' AND
f.version = 'V2018' AND
f.month = '01' AND
f.year = '2017'
Group by f.a,
f.b,
f.c
HAVING sum(d) != 0
You can resolve this by using HAVING clause: 您可以使用HAVING子句解决此问题:
SELECT a,
b,
c,
sum(d) as ftd
FROM items f
WHERE f.category = 'ANY' AND
f.version = 'V2018' AND
f.month = '01' AND
f.year = '2017'
Group by f.a,
f.b,
f.c
HAVING SUM(f.d)<>0
ORDER BY f.a,
f.b,
f.c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.