2014-02-21 210 views
0

我需要選擇狀態='過期'的另一個狀態爲'未售出'的bid-id有人可以幫忙嗎?從同一列中選擇2個值

SELECT *, 
     SelectBidID, DATENAME(mm, Date) AS Month 
FROM BID 
WHERE (Status = 'Won') 

回答

0

試試這個

SELECT *, SelectBidID, DATENAME(mm, Date) AS Month, 
     Case [Status] 
      When 'expired' Then 'sucessfull' 
      When 'unsold' Then 'unsucessfull' 
      --Else 'Unknown' 
     End As [Status] 
FROM BID 
WHERE [Status] = 'expired' 
     OR [Status] = 'unsold' 
+0

我需要分別在兩個值,如所有過期和全部流拍,我就會把這個圖表 – user3287068

+0

請。讓你的問題有更多的細節和簡潔。 – Jade

+0

你是什麼意思分開的,因爲你已經可以按狀態分開它們了? – Jade

0
WITH Unsold AS 
     (SELECT *, 
      Select BidID, DATENAME(mm, Date) AS Month 
      ,Status As U_Status 
    FROM BID 
    WHERE (Status = 'unsold') 
    ),Expired AS 
     (SELECT *, 
      SelectBidID, DATENAME(mm, Date) AS Month 
      ,Status as E_Status 
    FROM BID 
    WHERE (Status = 'expired') 
    ) 


    Select s.*, s.U_Status, e.E_Status from Unsold s 
    INNER JOIN Expired e ON s.SelectBidID =e.SelectBidID