Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql adding new column for the selection

Tags:

select

mysql

I have the following table

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

When I make a selection I want to add one more column.

For example

SELECT id,datenum, F1_baro_20_ FROM test

And I want to add a column, something like this:

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    |
+-----+------------------+-------------+------------+
like image 478
OHLÁLÁ Avatar asked Jul 13 '26 00:07

OHLÁLÁ


1 Answers

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

This even works with more complex expressions, like this:

SELECT id, datenum, F1_baro_20_, (IF id = 2 THEN 1 ELSE 0) AS id_is_two FROM test;
like image 89
Emil Vikström Avatar answered Jul 15 '26 13:07

Emil Vikström



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!