看板 Database 關於我們 聯絡資訊
※ 引述《bbsn (bbsn)》之銘言: : ※ 引述《greetmuta (愚零鬥武多)》之銘言: : : --問題一 : : select (case when (case when 2>1 then 'A' else 'B' end) ='A' then 'C' else : : 'D' end) as my_column : : --問題二 : : select * from test3 where price < (case when 2>1 then 50 else 20 end) : : 希望有幫上你的忙~ : 有關於問題一,我大致上修改成如下,不過會出來錯誤 : 錯誤:無法繫結多重部分 (Multi-Part) 識別碼 "B.redate" : select (case when B.redate is null then (case when B.des is null then : A.opdate else B.opdate end) else B.redate end) as opdate : from 資料表A as A join 資料表B as B on A.no=B.no : 有關於問題二,我寫我想表達的,不過會出來錯誤,我知道是在where 的那個opdate,不 : 過沒有辦法從as新的opdate出來的資料來選嗎? : 錯誤:模稜兩可的資料行名稱 'opdate' : select (case when B.redate is null then (case when B.des is null then : A.opdate else B.opdate end) else B.redate end) as opdate : from 資料表A as A join 資料表B as B on A.no=B.no where opdate='2013/05/05' : 再麻煩解答,謝謝~~ 直接把case條件式寫在where後試試 select * from 資料表A as A join 資料表B as B on A.no = B.no where (case when B.redate is null then (case when B.des is null then A.opdate else B.opdate end) else B.redate end) = '2013/05/05'; 如果不行那就要再包一層再過濾條件了 select T.opdate from (select (case when B.redate is null then (case when B.des is null then A.opdate else B.opdate end) else B.redate end) as opdate from 資料表A as A join 資料表B as B on A.no = B.no) as T where t.opdate = '2013/05/05'; from 資料表A as A join 資料表B as B on A.no = B.no where -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.164.90.36