【问题标题】:SQL Concat int to string in mariadbSQL Concat int 到 mariadb 中的字符串
【发布时间】:2021-12-30 09:50:49
【问题描述】:

我正在本地数据库 Mariadb 上的 XAMP 中工作,并希望将单词添加/连接到 int 这是我的查询

Select 'id:' + cast(Cid as varchar) from table where Cid is 3747;

结果应该是 id:3747

我在这里做错了什么?

【问题讨论】:

  • 1) where Cid = 3747
  • 2) concat('id: ', cast(Cid as varchar(11)))

标签: sql casting mariadb concatenation


【解决方案1】:

使用 CONCAT。
IS 运算符仅用于 [NOT] NULL。
F.e. select col from tbl where col IS NOT NULL

select concat('id:', Cid) as result
from table 
where Cid = 3747

但你也可以使用IN

select concat('id:', Cid) as result
from table 
where Cid in (3747) 

【讨论】:

    猜你喜欢
    • 2013-07-25
    • 2020-12-05
    • 2014-09-26
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 2019-04-29
    相关资源
    最近更新 更多