我需要选择
Select Bid Id,date
From Bid where
Status ='Won' as successful
还
Select Bid Id, date
From Bid where
Status =Null as unsuccessful
大家好我需要在我的表bid
中为状态选择两种类型,并显示id
我该怎么做?
答案 0 :(得分:0)
您可以使用CASE
:
Select Bid, Id,date,
WonStatus = CASE WHEN Status ='Won' THEN 'Successful' ELSE 'Unsuccessful' END
From Bid where
或者,如果要连接所有行,首先是成功的,然后是不成功的,请使用UNION ALL
:
Select Bid, Id,date
From Bid
Where Status ='Won' as successful
UNION ALL
Select Bid, Id,date
From Bid
Where Status IS NULL AS unsuccessful
修改:“如果想知道每月成功多少以及每月成功多少?”
然后这应该有效:
Select YEAR(date) AS B_Year,
MONTH(date) AS B_Month,
Count(*) AS Success_Count
From Bid
Where Status = 'Won'
GROUP BY YEAR(date), MONTH(date)
答案 1 :(得分:0)
SELECT Bid
, ID
, date
, CASE
WHEN status IS NULL THEN 'unsuccessful'
WHEN status = 'Won' THEN 'successful'
WHERE status = 'Won'
OR status IS NULL