疑难SQL语句问题!请教!

feiyafei2008 2010-02-27 12:03:55
'发贴统计
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。
...全文
52 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
-狙击手- 2010-02-27
  • 打赏
  • 举报
回复
sum(case when layer = 0 then 1 else 0 end) as 回贴次数,
sum(case when layer = 1 then 1 else 0 end) as 回贴次数


access 改用iff判断
-狙击手- 2010-02-27
  • 打赏
  • 举报
回复
select poster as 用户名,
sum(case layer = 0 then 1 else 0 end) as 回贴次数,
sum(case layer = 1 then 1 else 0 end) as 回贴次数
sum(len(message)) as 回贴字数
From dnt_posts1
where fid = 7 and postdatetime >= #02/01/2010#
group by poster
ACMAIN_CHM 2010-02-27
  • 打赏
  • 举报
回复
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
htl258_Tony 2010-02-27
  • 打赏
  • 举报
回复
select poster as 用户名,
sum(iif(layer = 0,1,0) as 发贴次数,
sum(iif(layer = 1,1,0) as 回贴次数
sum(len(message)) as 回贴字数
from dnt_posts1
where fid = 7 and postdatetime >= #02/01/2010#
group by poster

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧