• 全部
  • 基础类
  • 应用实例
  • 新技术前沿

多表连查SQL语句

nosuchtracter 2008-01-07 09:47:56
我有三个表。Content C,Catalog A,Branch B
现在要统计每个部门B所发布的信息数,俩种状态
SQL语句如下:
select B.Name,B.status,
sum(case when C.status <> 99 and A.Report = 1 then 1 else 0 end) pub_cnt,
sum(case when C.status = 1 and A.Report = 1 then 1 else 0 end) confirmed_cnt
from
Branch B
left outer join Content c
on B.Id = C.BranchId
left join Catalog A
on C.CatalogId = a.Id and B.Status<>99
and (datediff(s,C.commitdate,@EndTime)>0)
and (datediff(s,@StartTime,C.Commitdate)>0)
group by B.Name,B.status order by B.Name

但为什么B.Status<>99这句不起作用呢?会把表B种状态为99的也查询出来了
请问该如何写
...全文
51 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
nosuchtracter 2008-01-07
haha
老想别的地方晕了头了
结贴
回复
dobear_0922 2008-01-07
--try
select B.Name,B.status,
sum(case when C.status <> 99 and A.Report = 1 then 1 else 0 end) pub_cnt,
sum(case when C.status = 1 and A.Report = 1 then 1 else 0 end) confirmed_cnt
from
Branch B
left outer join Content c
on B.Id = C.BranchId
left join Catalog A
on C.CatalogId = a.Id
where B.Status<>99
and (datediff(s,C.commitdate,@EndTime)>0)
and (datediff(s,@StartTime,C.Commitdate)>0)
group by B.Name,B.status order by B.Name
回复
wzy_love_sly 2008-01-07
...
where
B.Status<>99
and (datediff(s,C.commitdate,@EndTime)>0)
and (datediff(s,@StartTime,C.Commitdate)>0)
group by B.Name,B.status order by B.Name
回复
chuifengde 2008-01-07
and B.Status<>99===>>Where B.Status<>99
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-01-07 09:47
社区公告
暂无公告