动态Sql语句肯定能实现,这几天写的太多了...楼主你随便搜搜就能找到类似的问题
解决方案 »
- 熟悉discuz!nt的朋友 麻烦帮我看下哈
- 怎么统计网站流量。
- 大家帮忙看看 我还得学什么才能做.net美工
- .net中 手动分页如何制作
- 定时刷新问题
- ASP.NET的状态管理问题(从C/S转到B/S一直有点晕)
- 查询一个表获得数据,存储到DataSet中。对应的数据库有可能改变,怎么样让DataSet里边的数据跟着刷新,并且排序不变。 谢谢
- byte[] 类型数据 可以用session来传递吗?
- 这个datagrid问题怎么解决?
- 怎样从sql数据库中取得一个数据库中的所有表名,并显示出来
- 求救:实现多个表的联合绑定在datagrid
- 编译器错误信息: BC30451: 名称“containter”未声明
(select p.points from points p where p.id=s.sid and p.cid in (select c.cid from course c where c.cname=’语文’) ) as ‘ 语文’,
(select p.points from points p where p.id=s.sid and p.cid in (select c.cid from course c where c.cname=’数学’) ) as ‘ 数学’,
(select p.points from points p where p.id=s.sid and p.cid in (select c.cid from course c where c.cname=’英语’) ) as ‘ 英语’
from student s where s.class=’001’
有种是这样做,有那个高手有更好的解法
if exists (select * from dbo.sysobjects where id = object_id(N'[tb]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [tb]
GOcreate table tb(单位名称 varchar(10),日期 datetime,销售额 int)
insert into tb
select 'A单位','2001-01-01',100
union all select 'B单位','2001-01-02',101
union all select 'C单位','2001-01-03',102
union all select 'D单位','2001-01-04',103
union all select 'E单位','2001-01-05',104
union all select 'F单位','2001-01-06',105
union all select 'G单位','2001-01-07',106
union all select 'H单位','2001-01-08',107
union all select 'I单位','2001-01-09',108
union all select 'J单位','2001-01-11',109/*-- 要求结果
日期 A单位 B单位 C单位 D单位 E单位 F单位 G单位 H单位 I单位 J单位
---------- ----- ----- ----- ----- ----- ----- ---- ---- ---- ------
2001-01-01 100 0 0 0 0 0 0 0 0 0
2001-01-02 0 101 0 0 0 0 0 0 0 0
2001-01-03 0 0 102 0 0 0 0 0 0 0
2001-01-04 0 0 0 103 0 0 0 0 0 0
2001-01-05 0 0 0 0 104 0 0 0 0 0
2001-01-06 0 0 0 0 0 105 0 0 0 0
2001-01-07 0 0 0 0 0 0 106 0 0 0
2001-01-08 0 0 0 0 0 0 0 107 0 0
2001-01-09 0 0 0 0 0 0 0 0 108 0
2001-01-11 0 0 0 0 0 0 0 0 0 109
--*//*-- 常规处理方法*/
declare @sql varchar(8000)
set @sql='select 日期=convert(varchar(10),日期,120)'
select @sql=@sql+',['+单位名称
+']=sum(case 单位名称 when '''+单位名称+''' then 销售额 else 0 end)'
from(select distinct 单位名称 from tb) a
exec(@sql+' from tb group by convert(varchar(10),日期,120)')
http://community.csdn.net/Expert/topic/5529/5529672.xml?temp=.6944544
xs,kc,fs
where
xs.class = kc.class
and
kc.cid=fs.cid
and
xs.sid=fs.sid
and
xs.class=1随便写的不知道是否正确。