排除t_sql中的行

时间:2019-07-18 13:23:04

标签: sql sql-server

我有一张桌子

enter image description here

我需要排除所有具有round( sum(QtyInvoiced),1) = 0 and round(sum(Amount),1) =0

的行

enter image description here

我尝试了以下脚本,但是它不起作用,如何纠正?

 select sum(    QtyInvoiced ) , sum(Amount) ,salesNumber 
    from invoicesales
   group by salesNumber 
    except 

    select sum( QtyInvoiced ) , sum(Amount) ,salesNumber 
    from invoicesales

    group by salesNumber 

    having round( sum(QtyInvoiced),1) = 0 and round(sum(Amount),1) =0

2 个答案:

答案 0 :(得分:3)

尝试使用<>不等于

,如下所示
select sum( QtyInvoiced ) , sum(Amount) ,salesNumber 
from invoicesales
group by salesNumber 
having round( sum(QtyInvoiced),1) <> 0 and round(sum(Amount),1)<>0

答案 1 :(得分:2)

如果您要排除这些行,也许您想要NOT

HAVING NOT(ROUND( SUM(QtyInvoiced),1) = 0 AND ROUND(SUM(Amount),1) = 0);

否则,您的SQL将完全按照您的要求执行 ,以返回行QtyInvoiced Amount之和等于 0(不排除那些相等的对象)。