Mysql 添加新列以供选择

发布于 2024-11-08 12:50:36 字数 813 浏览 0 评论 0原文

我有下表

+-----+------------------+-------------+
| 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    |
+-----+------------------+-------------+------------+

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    |
+-----+------------------+-------------+------------+

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剪不断理还乱 2024-11-15 12:50:36
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;
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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文