您好我需要从列中获取两种类型的值,该语句应显示如下,
Select bid-id
from bid
where status = 'Expired'
为Successful
和
Select bid-id
from bid
where status ='Unsold'
为Failed
,每个按datename(mm, date)
排序。
有人可以帮助我如何使这两个陈述在同一个声明中运行吗?
答案 0 :(得分: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]