易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL迷惑

CREATE TABLE [Test_xcmtmp] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[subject] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[Source] [numeric](18, 0) NULL
) ON [PRIMARY]
GO
INSERT INTO [Test_xcmtmp] ([name],[subject],[Source]) values (N'张三',N'语文',60)
INSERT INTO [Test_xcmtmp] ([name],[subject],[Source]) values (N'李四',N'数学',70)
INSERT INTO [Test_xcmtmp] ([name],[subject],[Source]) values (N'王五',N'英语',80)
INSERT INTO [Test_xcmtmp] ([name],[subject],[Source]) values (N'王五',N'数学',75)
INSERT INTO [Test_xcmtmp] ([name],[subject],[Source]) values (N'王五',N'语文',57)
INSERT INTO [Test_xcmtmp] ([name],[subject],[Source]) values (N'李四',N'语文',80)
INSERT INTO [Test_xcmtmp] ([name],[subject],[Source]) values (N'张三',N'英语',90)
Go

declare @sql varchar(8000)
---*********
set @sql = 'select name,'
select @sql = @sql + 'sum(case subject when '''+subject+''' then source else 0 end) as '''+subject+''','
from (select distinct subject from Test_xcmtmp) as a
select @sql = left(@sql,len(@sql)-1) + ' from Test_xcmtmp group by name'
--**********
exec(@sql)
go



相关问答:

sql server 存储过程循环赋值的问题

小弟是个新手 现在有个问题一直不能解决
例如
procedure produce_proc
    @p001 nvarchar(8000),
    @p002 nvarchar(8000),
    @p003 nvarchar(8000),
  & ......

关于group by的sql语句?

  with adod_dict do
    begin
    close;
    commandtext:='select bgqxcode,count(*) wjsl from wscl_wsda_file where wjnd=:tnd group by bgqxcode'; ......

sql 问题

DateTime startTime=DateTime(em_1.Text)
DateTime endTime=DateTime(em_2.Text)

string sql
sql = dw_1.GetSQLSelect()+"Where (StartTime> '"+startTime+"') and (EndTime ......

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

SQL字段,横向展开

请问各位,如何将SQl中,某字段中的值横向展开呢,
CASE WHEN

具体问题具体分析,看你要怎么展开

姓名  科目      成绩
张三  英语    90
李四  英语&nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号