SQL - Select 作为 FIELDNAME 为空?
SQL - Select null as FIELDNAME?
我遇到过一些代码
select null as UnitCost,
null as MarkUp
这到底是做什么用的?是否获取字段名称 unitcost 和 markup?
为什么要使用 "select null as..."?
新手抱歉。
谢谢。
只需将NULL
填充到那些选定的列
当您执行 Insert...Select
时很有用,您尝试插入的 Table 的列数可能比所选 table 的列数多,为方便起见,您可以使用 select null as col_name
让您尝试插入的列数与目标 table 具有的列相匹配。
该代码为值 null
添加了别名,并将其命名为 UnitCost
/MarkUp
。它没有从任何可用的 table.
中选择该列
当语句需要匹配列集时,您通常会看到这种情况,例如union all
.
select id, col1, col2, null as UnitCost, null as MarkUp
from table_1
union all
select id, null as col1, null as col2, UnitCode, MarkUp
from table_2
我遇到过一些代码
select null as UnitCost,
null as MarkUp
这到底是做什么用的?是否获取字段名称 unitcost 和 markup?
为什么要使用 "select null as..."?
新手抱歉。
谢谢。
只需将NULL
填充到那些选定的列
当您执行 Insert...Select
时很有用,您尝试插入的 Table 的列数可能比所选 table 的列数多,为方便起见,您可以使用 select null as col_name
让您尝试插入的列数与目标 table 具有的列相匹配。
该代码为值 null
添加了别名,并将其命名为 UnitCost
/MarkUp
。它没有从任何可用的 table.
当语句需要匹配列集时,您通常会看到这种情况,例如union all
.
select id, col1, col2, null as UnitCost, null as MarkUp
from table_1
union all
select id, null as col1, null as col2, UnitCode, MarkUp
from table_2