Sql中文插入
创建一张表,并且想表中插入中文和时间
CREATE TABLE [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(0x00009AF200000000 AS DateTime), N拜仁, N胜);INSERT [T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF300000000 AS DateTime), N奇才, N胜);INSERT [T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF300000000 AS DateTime), N湖人, N胜);INSERT [T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF400000000 AS DateTime), N拜仁, N负);INSERT [T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF200000000 AS DateTime), N拜仁, N负);INSERT [T_Scores] ([Date], [Name], [Score]) VALUES (CAST(0x00009AF600000000 AS DateTime), N奇才, N胜);
查询结果如图:
现在想实现如图的现实效果:
首先先建立一个返回分手的函数
create function num(@name nvarchar(50),@win nvarchar(50))returns intasbegindeclare @num intselect @num=count(Score) from T_Scores where name=@name and Score=@winreturn @numend
再在Sql查询中调用
select distinct(name),dbo.num(name,胜)as 胜,dbo.num(name,负)as 负 from T_Scores
显示效果如图:
相关新闻>>
- 发表评论
-
- 最新评论 更多>>