从同一列中选择2个值

时间:2014-02-21 01:39:30

标签: sql-server

我需要选择status ='expired'的bid-id和另一个status ='unsold'的人可以帮忙吗?

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

2 个答案:

答案 0 :(得分: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'

答案 1 :(得分: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