sql语句求教:表格查询结果如何纵向显示(100分)

  • 主题发起人 主题发起人 Geminiyc
  • 开始时间 开始时间
G

Geminiyc

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个表,xh相同的每3条记录一组(也可能少于3条)<br>xh &nbsp; sn &nbsp; &nbsp;a1 &nbsp; &nbsp;a2 &nbsp; &nbsp; a3 &nbsp; &nbsp; a4<br>1001 &nbsp;1 &nbsp; &nbsp;<br>1001 &nbsp;2 &nbsp;<br>1001 &nbsp;3 &nbsp;<br>1002 &nbsp;1 &nbsp;<br>1002 &nbsp;2 &nbsp;<br>1002 &nbsp;3 &nbsp; <br>1003 &nbsp;1 &nbsp;<br>1003 &nbsp;2 <br>我想对xh为某个具体值的3条记录(如xh=1001)的数值横向显示在表格中,并可以表格中对其值直接修改(DBGridEH)——<br>项目 &nbsp;sn1 &nbsp; sn2 &nbsp; sn3<br>a1<br>a2<br>a3<br>a4<br>这样的sql语句该如何写啊? (MS SQL Server)<br>谢谢
 
结束了。<br>没人来
 
U &nbsp;P.... U &nbsp; P...
 
楼主我也有同样的问题,加我QQ探讨一下吧376430458
 
CREATE TABLE [Test] (<br>  <br>  [id] [int] IDENTITY (1, 1) NOT NULL ,<br>  <br>  [name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,<br>  <br>  [subject] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,<br>  <br>  [Source] [numeric](18, 0) NULL<br>  <br>  ) ON [PRIMARY]<br>  <br>  GO<br>  <br>  INSERT INTO [test] ([name],[subject],[Source]) values (N'张三',N'语文',60)<br>  <br>  INSERT INTO [test] ([name],[subject],[Source]) values (N'李四',N'数学',70)<br>  <br>  INSERT INTO [test] ([name],[subject],[Source]) values (N'王五',N'英语',80)<br>  <br>  INSERT INTO [test] ([name],[subject],[Source]) values (N'王五',N'数学',75)<br>  <br>  INSERT INTO [test] ([name],[subject],[Source]) values (N'王五',N'语文',57)<br>  <br>  INSERT INTO [test] ([name],[subject],[Source]) values (N'李四',N'语文',80)<br>  <br>  INSERT INTO [test] ([name],[subject],[Source]) values (N'张三',N'英语',100)<br>  <br>  Go<br>   <br>  &nbsp;<br><br><br>  交叉表语句的实现:<br>  <br>  用于:交叉表的列数是确定的<br>  <br>  select name,sum(case subject when '数学' then source else 0 end) as '数学',<br>  <br>  sum(case subject when '英语' then source else 0 end) as '英语',<br>  <br>  sum(case subject when '语文' then source else 0 end) as '语文'<br>  <br>  from test<br>  <br>  group by name
 
接受答案了.
 

Similar threads

后退
顶部