求教一个博客系统中的SQL查询语句,环境为SQL Server 2008 R2

2025-02-26 20:39:29
推荐回答(1个)
回答1:

select p.pid,p.p_title,p.p_content,ca.cid c_id,ca.c_name,
select tag1+','tag2' as tags
from
(

select 
max( case tag when '标签1' then tag else 'null' end) as tag1,
max(case tag when '标签2' then tag else 'null' end) as tag2
from posttags
group by pid
) t1
) t2
,
count(*) as commentsCount
from posts p,comments com,category ca
where p.pid=com.pid
and com.cid=ca.cid
group by p.pid,p.p_title,p.p_content,ca.cid,ca.c_name;

没有环境测试,你亲自测试一下吧