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