我有以下查询,它不会产生任何结果,但没有错误。我试图选择所有不是“特色新闻稿”并且属于某种类型的页面,例如“公告”。
SELECT parent.* FROM [cq:Page] AS parent INNER JOIN [nt:base]
AS child ON ISCHILDNODE(child,parent) WHERE ISDESCENDANTNODE(parent, '/content/acme/en_US/site-content/content-modules/resources/press-releases')
AND (NOT CONTAINS(child.[cq:tags], 'acme- www:FeaturedResources/FeaturedPressRelease*'))
AND (CONTAINS(child.[cq:tags], 'acme-www:PressReleaseType/Announcement'))
AND child.[pressReleaseDate] > CAST('2015-01-01T00:00:00.000Z' AS DATE)
AND child.[pressReleaseDate] < CAST('2016-01-01T00:00:00.000Z' AS DATE)
order by child.[jcr:title]
如果我删除行“AND(NOT CONTAINS ...”,我得到正确的结果。另外,如果我把那条线放回去,并删除线“AND(CONTAINS(...”我得到正确的结果。但是同时在那里有两条线给我没有结果。有些页面应该是合格的,即它们不是特色新闻稿,它们是类型公告,所以在我看来逻辑上这应该有效。
有谁知道查询无效的原因?我是SQL2的新手,我在网上找不到任何类似的例子,只是一般术语的描述。
谢谢!
答案 0 :(得分:0)
我不确定你的某个标签中的splat是否应该是通配符,但如果是这样,可能会使用LIKE%语法。 cq:tags是一个String [],但我没有运气使用像这样的包含...希望其他人可以说出原因。你可以试试这样的......
SELECT parent.* FROM [cq:Page] AS parent INNER JOIN [nt:base]
AS child ON ISCHILDNODE(child,parent) WHERE ISDESCENDANTNODE(parent, '/content/acme/en_US/site-content/content-modules/resources/press-releases')
AND NOT (child.[cq:tags] = 'acme-www:FeaturedResources/FeaturedPressRelease')
AND child.[cq:tags] = 'acme-www:PressReleaseType/Announcement'
AND child.[pressReleaseDate] > CAST('2015-01-01T00:00:00.000Z' AS DATE)
AND child.[pressReleaseDate] < CAST('2016-01-01T00:00:00.000Z' AS DATE)
order by child.[jcr:title]