【发布时间】:2014-02-27 18:52:00
【问题描述】:
查询
select * from notice join noticeconcerned using(notice_id) where (nconcerned_section = 'IT' and nconcerned_batch = 2010) or (nconcerned_batch = 2010) order by n_removeby
结果
a http://www.4shared.com/download/sgAkE2pKce/notice1.png?lgfp=3000
我想显示(2010 批次和 CS 部分)或(2010 批次但没有部分,即空部分)的学生记录所以在这种情况下,应该只显示一行。
我的尝试
select * from notice join noticeconcerned using(notice_id) where case when (nconcerned_section = 'CS' and nconcerned_batch = 2010) then(____What to use here?) END or case when (nconcerned_batch = 2010 and nconcerned_section=null) then(___what to use here?) END order by n_removeby
如果您能解释如何将case statement 用于where clause,那将非常有帮助。我发现了一些关于它的帖子,但这让我感到困惑。
【问题讨论】:
-
请放一些数据样本(notice 和 noticeconcerned),以及你期望的结果!
-
我的错误是当我将数据插入表时,我没有插入
null,而是插入了' ',即space。所以is null对我不起作用。我更新了该表并使用了查询。它按预期工作。
标签: sql postgresql case where-clause conditional-statements