求助~~如何实现分组统计的时候,没有记录的组可以显示为0,而不是不显示
按照TheYear分组,统计每年Numbers<60的条数;select TheYear,Count(*) from Test Where Numbers<60 Group BY TheYear
得到的结果是:
TheYear Numbers
1999 1
如何才能得到
TheYear Numbers
1999 1
2000 0
PS:我用ISNULL(count(*),0)也没实现想要的效果~~~请各位大侠出手相助~~
表结构如下:
CREATE TABLE [dbo].[Test] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[TheYear] [int] NULL ,
[Numbers] [int] NULL
) ON [PRIMARY]
GO
insert into Test(TheYear,TotalScore) values (1999,87)
insert into Test(TheYear,TotalScore) values (1999,33)
insert into Test(TheYear,TotalScore) values (2000,85)
insert into Test(TheYear,TotalScore) values (2000,89)