首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

SQL疑难有关问题!请问

2012-02-15 
SQL疑难问题!请教发贴统计select poster as 用户名,count(*) as 发贴次数,sum(len(message)) as 发贴字数

SQL疑难问题!请教
'发贴统计
select poster as 用户名,count(*) as 发贴次数,sum(len(message)) as 发贴字数 From dnt_posts1 where fid = 7 and layer = 0 and postdatetime >= #02/01/2010# group by poster

'回贴统计
select poster as 用户名,count(*) as 回贴次数,sum(len(message)) as 回贴字数 From dnt_posts1 where fid = 7 and layer = 1 and postdatetime >= #02/01/2010# group by poster

怎么能将其合并成一条: “用户名,发贴次数,发贴字数,回贴次数,回贴字数”。

数据库是ACCESS。


[解决办法]

SQL code
select poster as 用户名,    sum(iif(layer = 0,1,0)) as 发贴次数,sum(iif(layer = 0,len(message),0)) as 发贴字数     sum(iif(layer = 1,1,0)) as 回贴次数,sum(iif(layer = 1,len(message),0)) as 回贴字数 From dnt_posts1 where fid = 7 and postdatetime >= #02/01/2010# group by poster 

热点排行