我有 2 张桌子
表 1
ID
1
2
3
表 2
level
1
级 2
级 3 级
我需要
id | level
1 | 1 级
2 | 2 级
3 | 3级
根据您提出问题的方式,第二张表不是必需的。您可以将这些值连接在一起:
select id, concat('level ', cast(id as varchar(255))) as level
from t
在某些数据库中,您可能会使用||
or+
运算符而不是concat()
.
select ID, [level]
from tbl1
cross join tbl2
where CHARINDEX(cast(id as varchar),[level],0) > 0