我想 make join 2 tables 但在 2 事物上不是典型的相同,比如 slug 和 path , slug abc 和 path /article

I want make join 2 tables but on 2 things not the typical same, like slug and path , slug abc , and path /article

我有 2 tables 一个名称日志包含(路径和日志 ID 等) 第二 table 篇文章包含 (slug, id, title)

我想在日志上查询 make join on articles.slug。路径

(问题出在path=/articles/slug)

我如何加入这个

我找到了名为“% %”的模式 我尝试在加入中使用它,但我不知道如何加入 log.path = '/article/' + log.slug

  log.path                       log.count(path)view  article.slug   
-------------------------------------+- -------|--------------------
/                                   | 479121  |   
/article/candidate-is-jerk          | 338647  |   candidate-is-jerk
/article/bears-love-berries         | 253801  |   bears-love-berries
/article/bad-things-gone            | 170098  |   bad-things-gone

我需要加入这个 log.path = '/article/' + log.slug

你可以这样加入

on log.path like concat('%article%',article.slug);

您可以在 SQL 中将此 join 表示为:

from log l join
     article a
     on l.path = concat('/article/', a.slug);

或(使用标准语法):

from log l join
     article a
     on l.path = '/article/' || a.slug;

第二种形式将通过忽略 null 值来处理它们。第一个将(通常但它可能取决于数据库)return null 如果任一值为 null。