Sql server php mysql中的两列总和选择查询
我想输出Sql server php mysql中的两列总和选择查询,sql-server,Sql Server,我想输出0notNULL 您可以使用ISNULL()函数: select ( select ISNULL(sum(NetAmount) ,0) from Table1 where pid = '1') - ( select ISNULL(sum(NetAmount),0) from Table1 where cid = '1') select ( select
0
notNULL
您可以使用
ISNULL()
函数:
select ( select ISNULL(sum(NetAmount) ,0)
from Table1
where pid = '1') -
( select ISNULL(sum(NetAmount),0)
from Table1
where cid = '1')
select
( select coalesce(sum(NetAmount), 0)
from Table1
where pid = '1') -
( select coalesce(sum(NetAmount), 0)
from Table1
where cid = '1')
您可以使用
ISNULL()
函数:
select ( select ISNULL(sum(NetAmount) ,0)
from Table1
where pid = '1') -
( select ISNULL(sum(NetAmount),0)
from Table1
where cid = '1')
select
( select coalesce(sum(NetAmount), 0)
from Table1
where pid = '1') -
( select coalesce(sum(NetAmount), 0)
from Table1
where cid = '1')
对任何算术运算应用
null
将导致null
。您可以使用coalesce
功能解决此问题:
select ( select ISNULL(sum(NetAmount) ,0)
from Table1
where pid = '1') -
( select ISNULL(sum(NetAmount),0)
from Table1
where cid = '1')
select
( select coalesce(sum(NetAmount), 0)
from Table1
where pid = '1') -
( select coalesce(sum(NetAmount), 0)
from Table1
where cid = '1')
对任何算术运算应用
null
将导致null
。您可以使用coalesce
功能解决此问题:
select ( select ISNULL(sum(NetAmount) ,0)
from Table1
where pid = '1') -
( select ISNULL(sum(NetAmount),0)
from Table1
where cid = '1')
select
( select coalesce(sum(NetAmount), 0)
from Table1
where pid = '1') -
( select coalesce(sum(NetAmount), 0)
from Table1
where cid = '1')
您使用MySQL还是SQL Server?因为tag是MySQL,Fiddle是sqlserver。在MySQL中,您可以使用
IFNULL()
函数。如果您无法理解您的输出,请您简单介绍一下,您使用的是MySQL还是SQL Server?因为tag是MySQL,Fiddle是sqlserver。在MySQL中,您可以使用IFNULL()
函数。如果您无法理解您的输出,请您向我简要介绍一下。很高兴能提供帮助