创建一张表,并且想表中插入中文和时间

CREATETABLE[T_Scores](
[Date][datetime]NULL,
[Name][nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[Score][nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL
);
INSERT[T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF200000000ASDateTime), N'拜仁', N'');
INSERT[T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF300000000ASDateTime), N'奇才', N'');
INSERT[T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF300000000ASDateTime), N'湖人', N'');
INSERT[T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF400000000ASDateTime), N'拜仁', N'');
INSERT[T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF200000000ASDateTime), N'拜仁', N'');
INSERT[T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF600000000ASDateTime), N'奇才', N'');

查询结果如图:

现在想实现如图的现实效果:

首先先建立一个返回分手的函数

createfunction num
(
@namenvarchar(50),@winnvarchar(50))
returnsint
as
begin
declare@numint
select@num=count(Score) from T_Scores where name=@nameand Score=@win
return@num
end

再在Sql查询中调用

selectdistinct(name),dbo.num(name,'')as'',dbo.num(name,'')as''from T_Scores

显示效果如图:

posted on 2011-06-24 15:14  高兴happy  阅读(894)  评论(0编辑  收藏  举报