2011-05-18 91 views
3

增加新的專欄中,我有如下表MySQL的選擇

+-----+------------------+-------------+ 
| id | datenum   | F1_baro_20_ | 
+-----+------------------+-------------+ 
| 1 | 734152.000000000 |  1005.21 | 
| 2 | 734152.006944445 |  1005.26 | 
+-----+------------------+-------------+ 

當我做出選擇我要補充一個列。

例如

SELECT id,datenum, F1_baro_20_ FROM test 

而且我想增加一列,這樣的事情:

SELECT id,datenum, F1_baro_20_, new_column=1 FROM test 

+-----+------------------+-------------+------------+ 
| id | datenum   | F1_baro_20_ |new_column | 
+-----+------------------+-------------+------------+ 
| 1 | 734152.000000000 |  1005.21 |  1 | 
| 2 | 734152.006944445 |  1005.26 |  1 | 
+-----+------------------+-------------+------------+ 

回答

9
SELECT id, datenum, F1_baro_20_, 1 AS new_column FROM test; 

這甚至有更復雜的表達式的作品,這樣的:

SELECT id, datenum, F1_baro_20_, (IF id = 2 THEN 1 ELSE 0) AS id_is_two FROM test; 
+0

葉,我也試過這一個括號SELECT id,datenum,F1_baro_20_,(1 AS new_column)FROM test;這就是問題所在。謝謝。 – 2011-05-18 14:58:48