如何将一个 table 中的部分字符串与另一个 table 中的 ID 匹配?

How to match partial strings in one table to ID in another table?

我需要找到一种方法来找出谁查看、共享和下载了文档。

我需要想办法将 logDetail table 中字符串中的文件 ID 与另一个 table 中的文档 ID 相匹配,这样我就可以匹配 files/document 这些 ID 的名称。

下面显示了我的 table 的一部分。

日志详情

文件

如果id总是在log的末尾,可以在join条件中使用like

select *
from logdetail ld
inner join documents d 
    on l.logdetail like concat('%', d.documentid)

如果字符串格式是固定的,你甚至可以更精确:

select *
from logdetail ld
inner join documents d 
    on l.logdetail = concat('Load Shared Document with ID ', d.documentid)

嗯。 . .你可以这样做:

select ld.*
from logDetail ld join
     documents d
     on ld.logDetail like concat('% ID ', d.documentId);

您显示的所有 logDetail 记录都以 ' ID <number>' 结尾,因此这与该模式匹配。