参考这个帖子,我试了半天也没弄出来http://community.csdn.net/Expert/TopicView3.asp?id=5643256
现在我要增加一个表的关联
tableC
userID,userName
1 admin
2 test
3 test2
现在我要增加一个表的关联
tableC
userID,userName
1 admin
2 test
3 test2
解决方案 »
- TexBox框
- 大家帮忙看看。自动分页时有时第一页和第三页内容一样,而且很慢,主要为了实现经过用户查询后将查询结果分页,并根据用户选择的内容充填到文本框内。
- 如何限制图片显示的大小?
- 想问下上传文件的放置问题
- 谁帮我看看这是什么问题啊??数据库的
- 正在努力完成的网站,请大虾给予批评指教!!!
- 请问各位牛,怎么在asp.net中设置ifram中的页面输出内容不被查看。
- asp.net web api如何获取调用Action之前的异常?
- 请一个问题,在ASP中如何把几个recordset中的数据合并到一个RS中
- 为什么自定义服务器控件没有Enable这个属性?
- ~~~~~~~~刷新页面问题~~~~~~~~~`
- 100分,100分,100分,100分,练习Cookie的Domain时,总是生不成Cookie,对了立即给分。
drop table tbTest1
if object_id('tbTest2') is not null
drop table tbTest2
if object_id('tbTestC') is not null
drop table tbTestC
GO
create table tbTest1(aid int,name varchar(10),modelsId int)
insert tbTest1
select 1,'发贴',1 union all
select 2,'回贴',1 union all
select 3,'消息',2 union all
select 4,'申请',3
create table tbTest2(userid int,aid int,action varchar(10),content varchar(10))
insert tbTest2
select 1, 1, 'add', 'fsfdsfsd' union all
select 1, 2, 'add', 'sdfsfasf' union all
select 2, 3, 'add', 'adfsfddf' union all
select 3, 3, 'add', 'adfssddf'
create table tbTestC(userid int,userName varchar(10))
insert tbTestC
select 1, 'admin' union all
select 2, 'test' union all
select 3, 'test2'----汇总
declare @sql varchar(8000)
set @sql = 'select a.userid,c.userName'
select @sql = @sql + ',' + name + '=sum(case b.name when ''' + name + ''' then 1 else 0 end)'
from tbTest1 group by name
set @sql = @sql + ' from tbTest2 as a
left join tbTest1 as b on a.aid = b.aid
LEFT JOIN tbTestC as c on a.userid = c.userid
group by a.userid,c.userName'
EXEC(@sql)----清除测试环境
drop table tbTest1,tbTest2,tbTestC
/*结果
userid userName 发贴 回贴 申请 消息
----------- ---------- ----------- ----------- ----------- -----------
1 admin 1 1 0 0
2 test 0 0 0 1
3 test2 0 0 0 1
*/