0

我正在尝试添加一个 if 语句,例如如果标题是这样,则排除那些文件名,否则文件名 = bla bla。但显然不起作用,有什么想法吗?

SELECT
    SUM(streamlength)
FROM
    files,
    filemetadata
where
    files.id = filemetadata.id 
    AND title like 'abc'
    and (Time > '2013-01-01' and Time < '2013-08-06' )
    and 
    if((title like 'abc' AND Time > '2013-02-22'),
    (filename NOT like '%20121129%'
    AND filename NOT like '%20121204%'
    AND filename NOT like '%20121214%'
    AND  filename NOT like '%20121219%'
    AND filename NOT like '%20130109%'
    AND  filename NOT like '%20130114%'),filename like 
                   '%1111111%')
4

1 回答 1

3

如果我正确阅读了 SQL 的意图:

SELECT
SUM(streamlength)
FROM
files,
filemetadata
where
files.id = filemetadata.id 
AND title like 'abc'
and (Time > '2013-01-01' and Time < '2013-08-06' )
and 
(
  ( 
    (title like 'DE-PIAE78' AND Time > '2013-02-22')
    AND
    (filename NOT like '%20121129%'
     AND filename NOT like '%20121204%'
     AND filename NOT like '%20121214%'
     AND  filename NOT like '%20121219%'
     AND filename NOT like '%20130109%'
     AND  filename NOT like '%20130114%')
  )
  OR
  (
    NOT ( (title like 'DE-PIAE78' AND Time > '2013-02-22') )
    AND ( filename like '%1111111%')
  )
)

这会根据(title like 'DE-PIAE78' AND Time > '2013-02-22')真假匹配不同的文件名。

一些 SQL 变体支持 IF 语句,但并非全部都支持。

于 2013-09-03T22:28:34.260 回答