1

是否可以将这 2 个查询更改为 1 个?

查询 #1:

UPDATE  `pvdownloader`.`posts`
SET  `exists` =  'y'
WHERE source = ANY (SELECT source FROM dbdownloader.posts)
  AND `mangacount` = 0
  AND NOT `exists` = 'm'

查询 #2:

UPDATE `pvdownloader`.`posts`
SET  `exists` =  'n'
WHERE `exists` = 'u'
  AND `mangacount` = 0

我假设可以用 IF/ELSE 制作这样的东西,但我根本不知道如何使用它:<

4

1 回答 1

5

也许这样的事情会起作用:

update
  pvdownloader.posts
set
  exists =
    case
      when source = any(select source from dbdownloader.posts) and mangacount = 0 and exists != 'm' then 'y'
      when exists = 'u' and mangacount = 0 then 'n'
    end
where 
  (source = any(select source from dbdownloader.posts) and mangacount = 0 and exists != 'm')
  or
  (exists = 'u' and mangacount = 0)
;

正如@MostyMostacho 所建议的那样,我冒昧地改变了你的逻辑,没有双重否定。

于 2012-04-15T00:28:36.880 回答