我有一个查询,其中有两个我想合并为新列的字段。在Excel上,它像这样
=CONCATENATE([@CompanyID],[@Year],[@month])
但我不知道如何在sql上创建此公式,输出将像
新ID = 88201911 aka 88 = companyID 2019 =年11 =月
范例程式码
Select
companyID,
invoicedate,
month(invoicedate) as month,
year(invoicedate) as year,
concat('companyID','month','year')
from accounting
您不能在same中重复使用列别名select
。因此,您需要重复以下表达式:
month(invoicedate) as month,
year(invoicedate) as year,
concat(companyID, month(invoicedate), year(invoicedate))
此外,切勿使用单引号引用列。它们仅应用于字符串和日期常量。
非常感谢你!