2014-02-21 175 views
0

你好,我需要從一列得到兩種類型的值,該聲明應顯示爲遵循,爲SQL Server Select語句

Select bid-id 
from bid 
where status = 'Expired' 

Successful

Select bid-id 
from bid 
where status ='Unsold' 

Failed,每一個訂購datename(mm, date)

有人可以幫助我如何使這兩個陳述在同一個陳述中運行嗎?

回答

4

試試這個:

SELECT 
[bid-id], 
CASE WHEN Status = 'Expired' THEN 
    'Successful' 
WHEN Status = 'Unsold' THEN 
    'Failed' 
END AS [Status] 
FROM 
    [bid] 
ORDER BY datename(mm, date) 

如果您需要在單獨的列值,使用:

SELECT 
(SELECT [Bid-id] FROM [bid] WHERE Status = 'Expired' ORDER BY datename(mm, date)) AS [Successful], 
(SELECT [Bid-id] FROM [bid] WHERE Status = 'Unsold' ORDER BY datename(mm, date)) AS [Failed] 
FROM 
[Bid] 
+0

告訴附近關鍵字的情況下 – user3287068

+0

裹投標的ID錯誤括號內爲上述更新。 –

+0

你好值顯示在列名狀態,我不需要,我需要成功和失敗顯示在一個單獨的列中,因爲你可以檢查結果 – user3287068