2017-02-28 3 views
1

大文字と小文字を区別して1つの列にある3つの異なる列のデータを選択したので、ここでフィルタリングしたいところがわかります。私はそれをすることができません。 解決策を持っている人なら誰でも共有できます。どのようにこのクエリで操作を実行できますか?複数の列のレコードを持つ列にwhere句を実行したいですか?出来ますか?

select 
    *, 
    case 
     when b.Booking_Status = 'd' then 'Draft' 
     when b.Booking_Status = 'r' then 'Reviewed' 
     when b.Booking_Status = 'a' then 'Verified' 
    end as Status_b, 
    case 
     when b.Booking_Status = 'd' then b.Add_By 
     when b.Booking_Status = 'r' then b.Review_By 
     when b.Booking_Status = 'a' then b.Verify_By 
    end as Status_By, 
    case 
     when b.Booking_Status = 'd' then b.Add_At 
     when b.Booking_Status = 'r' then b.Review_At 
     when b.Booking_Status = 'a' then b.Verify_At 
    end as Status_Add 
from 
    Booking b 
inner join 
    Booked_Units bu on b.Booking_Id = bu.BU_Booking_Id 
inner join 
    Enq_Line e on b.Booking_Enqh_Id = e.Enql_Enqh_Id 
where 
    Status_Add > GETDATE() 
+0

あなたは代わりに '' WHERE'のHAVING'を試したことがありますか? –

+0

これらのdbmsタグをすべて削除しました。それらの1つを戻してください! – jarlh

+0

質問を改善するためにこのリンクをご覧ください:https://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/ – TheGameiswar

答えて

1
select * 
    ,case when b.Booking_Status = 'd' then 'Draft' 
      when b.Booking_Status = 'r' then 'Reviewed' 
      when b.Booking_Status = 'a' then 'Verified' 
    end as Status_b 
    ,case when b.Booking_Status = 'd' then b.Add_By 
      when b.Booking_Status = 'r' then b.Review_By 
      when b.Booking_Status = 'a' then b.Verify_By 
    end as Status_By 
    ,case when b.Booking_Status = 'd' then b.Add_At 
      when b.Booking_Status = 'r' then b.Review_At 
      when b.Booking_Status = 'a' then b.Verify_At 
    end as Status_Add 
    from Booking b 
    inner join Booked_Units bu on b.Booking_Id = bu.BU_Booking_Id 
    inner join Enq_Line e on b.Booking_Enqh_Id = e.Enql_Enqh_Id 
    where case when b.Booking_Status = 'd' then b.Add_At 
      when b.Booking_Status = 'r' then b.Review_At 
      when b.Booking_Status = 'a' then b.Verify_At 
    end > GETDATE() 

または

select * from (
select * 
    ,case when b.Booking_Status = 'd' then 'Draft' 
      when b.Booking_Status = 'r' then 'Reviewed' 
      when b.Booking_Status = 'a' then 'Verified' 
    end as Status_b 
    ,case when b.Booking_Status = 'd' then b.Add_By 
      when b.Booking_Status = 'r' then b.Review_By 
      when b.Booking_Status = 'a' then b.Verify_By 
    end as Status_By 
    ,case when b.Booking_Status = 'd' then b.Add_At 
      when b.Booking_Status = 'r' then b.Review_At 
      when b.Booking_Status = 'a' then b.Verify_At 
    end as Status_Add 
    from Booking b 
    inner join Booked_Units bu on b.Booking_Id = bu.BU_Booking_Id 
    inner join Enq_Line e on b.Booking_Enqh_Id = e.Enql_Enqh_Id 
    ) as allResults 
    where allResults.Status_Add > GETDATE() 
+0

ありがとうございますそれは非常に良い – Quentin

0

のコンボを使用し、および/または:

where 
(b.Booking_Status = 'd' and b.Add_At > GETDATE()) 
or 
(b.Booking_Status = 'r' and b.Review_At > GETDATE()) 
or 
(b.Booking_Status = 'a' and b.Verify_At > GETDATE()) 
+0

この作品をありがとう.. – Quentin

関連する問題