【问题标题】:mySQL version of 'with' clause'with' 子句的 mySQL 版本
【发布时间】:2010-12-26 13:18:44
【问题描述】:

我的查询目标是在数据库中搜索一个长字符串。为了加快这个过程,longstring 表的所有记录在同一记录上都有该字符串的哈希值。我想首先在表中找到我的搜索字符串的散列等于longstring 表上的散列的所有记录。然后在我有了那个数据集之后,我想比较实际的字符串(因为哈希并不总是唯一的)。

现在在 oracle 或 mssql 中我会这样做...

with dataset as (
  select long_string
  from longstring
  where hash = 'searchhash'
) select *
from dataset
where long_string = 'searchstring'

... 但是 mysql 不支持 'with' 子句。那么我在 mysql 中最好的选择是什么?

提前致谢!

【问题讨论】:

标签: mysql with-clause


【解决方案1】:

您可以通过子选择来做到这一点:

select *
from (
  select long_string
  from longstring
  where hash = 'searchhash'
) AS dataset
where long_string = 'searchstring'

【讨论】:

    【解决方案2】:

    这与 AND 子句相同。

    SELECT  *
    FROm longstring
    WHERE hash = 'searchhash'
    AND long_string = 'searchstring'
    

    【讨论】:

      猜你喜欢
      • 2010-09-24
      • 2010-11-16
      • 2019-07-29
      • 2021-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      相关资源
      最近更新 更多