简体   繁体   English

我想使用 SELECT 查询添加一个新列,并从 SQL 中的多个列中获取最新值

[英]I want to add a new column using SELECT query and get a latest value from multiple columns in SQL

Outcome1 结果1 Outcome2 结果2 Outcome3 结果3 Outcome4 结果4 DESIRED OUTCOME 期望的结果 CR CR CR C C CR CR CR N ñ CR N ñ CR CR C C C C C C C C C C C C C C CC 抄送 CC 抄送 CR CC 抄送 CC 抄送 CR

It seems you simply need the first not-null value.看来您只需要第一个非空值。 If so, You can use COALESCE function -如果是这样,您可以使用 COALESCE function -

SELECT COALESCE(Outcome1, Outcome2, Outcome3, Outcome4)
  FROM your_table;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL查询以获取按列分组的列的最新非空值 - SQL query to get latest non null value of columns grouping by a column 如果两个现有列匹配,则SQL查询添加新列,并从另一列添加值 - SQL query add new column if two existing columns matches and add value from another column Select 使用 SQL 查询的列中的最新年份 - Select the latest year in a column using SQL query SQL如果该值类似于多个列,则选择该列 - SQL Select the column if the value is like with multiple columns 向 Laravel 中的选择查询添加一个带有值的新列 - Add a new column with a value to the select query in Laravel 我想在从 sql 获得的 json 中插入新值 - I want insert new value in json which get from sql 当数据中有空值时,sql查询从多列中获取最新数据 - sql query to get latest data from multiple columns when there are nulls in the data 使用选择查询中的值作为新列的名称,将新列添加到现有TABLE中 - Add new columns into a existing TABLE using the values from a select query as the name of the new columns PHP读取SQL查询-选择2个值-在特定的行值上运行一些数学运算将值添加到新列? - Php Read SQL Query - Select 2 Values - Run Some Maths On Specific Row Value Add Value To New Column? MySQL:Select 多列,但每个不同值的最新值为一列 - MySQL: Select multiple columns but with the latest value of one column for each distinct value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM