在SQL Server中,如何获得count,group by为具有值或NULL或空的列?Select count,group by query is not picking records for NULL and Empty String Column Values
该查询未返回NULL和空字符串值。它只有在BillType
上有一些值时才会返回。
select count(BillType), BillType
from Bills
group by BillType
在SQL Server中,如何获得count,group by为具有值或NULL或空的列?Select count,group by query is not picking records for NULL and Empty String Column Values
该查询未返回NULL和空字符串值。它只有在BillType
上有一些值时才会返回。
select count(BillType), BillType
from Bills
group by BillType
或许,这将有助于
Select BillType
,count(*)
From Bills
Group by BillType
这可能是因为你是Count
-ing比尔类型,而不是行。第一次尝试这样的:
Select BillType, count(*)
From Bills
Group By BillType
,但如果不工作(我已经到SQL Server无法访问),这将肯定...
Select coalesce(BillType, 'Null'), count(*)
From Bills
Group By coalesce(BillType, 'Null')
谢谢约翰,是的,它的工作原理。为了测试目的,我添加了示例查询。 – goofyui
@goofyui示例数据是一个很好的接触,但我对这一个非常有信心:) –
是的,你是。我非常感谢你的patindex帮助。包括样品将有助于每个人 – goofyui