2011-03-18 66 views

回答

1

你將不得不使用CASE語句,如:

SELECT id, 
     (CASE WHEN id=1 THEN 200 ELSE 100 END) AS NewCol 
... 
FROM Table 
1
select id, case when id = 1 then 200 else 100 end as newcol from table 
0

你不能。該列不在表中創建,它只存在於結果集中。

您可以在其中進行計算,或使用大小寫語句。

0

如果您只是想根據ID選擇不同的值。

select id, case 
when id = 1 then 100 
when Id = 2 then 200 end 
as newcol from table 

我還沒有測試過這個,但可能這應該工作。

+0

您可能應該使用'CASE'語句的正確語法,雖然... – JNK 2011-03-18 14:42:21

+0

@JNK,是的,我同意。 – WorkerThread 2011-03-18 14:46:05

0
select case "newcol" when id=1 then "newcol" =200