此查询仍然返回空标题字段?
这个查询工作完美,除了它仍然返回空白标题字段:
SELECT
DISTINCT( TRIM( LEFT(title,
IF( LOCATE('10 Pack', title), LOCATE('10 Pack', title) - 1,
IF( LOCATE('100 Classic', title), LOCATE('100 Classic', title) - 1,
IF( LOCATE('100 Favourite', title), LOCATE('100 Favourite', title) - 1,
IF( LOCATE('DVD', title), LOCATE('DVD', title) - 1,
IF( LOCATE('Bluray', title), LOCATE('Bluray', title) - 1,
IF( LOCATE('Series', title), LOCATE('Series', title) - 1,
IF( LOCATE('20 ', title), LOCATE('20 ', title) - 1,
999 )))))))))),
main_category,
genre,
actors
FROM
PRprodINFO
WHERE
((main_category = 'Films')
AND (length(title) > 2))
GROUP BY title
也尝试过:
SELECT
DISTINCT( TRIM( LEFT(title,
IF( LOCATE('10 Pack', title), LOCATE('10 Pack', title) - 1,
IF( LOCATE('100 Classic', title), LOCATE('100 Classic', title) - 1,
IF( LOCATE('100 Favourite', title), LOCATE('100 Favourite', title) - 1,
IF( LOCATE('DVD', title), LOCATE('DVD', title) - 1,
IF( LOCATE('Bluray', title), LOCATE('Bluray', title) - 1,
IF( LOCATE('Series', title), LOCATE('Series', title) - 1,
IF( LOCATE('20 ', title), LOCATE('20 ', title) - 1,
999 )))))))))),
main_category,
genre,
actors
FROM
PRprodINFO
where
((main_category = 'Films')
AND (title <> ''))
GROUP BY title
但仍然返回空白标题字段行...任何想法为什么?
谢谢达伦
this query works perfectly apart from it still returns blank title fields:
SELECT
DISTINCT( TRIM( LEFT(title,
IF( LOCATE('10 Pack', title), LOCATE('10 Pack', title) - 1,
IF( LOCATE('100 Classic', title), LOCATE('100 Classic', title) - 1,
IF( LOCATE('100 Favourite', title), LOCATE('100 Favourite', title) - 1,
IF( LOCATE('DVD', title), LOCATE('DVD', title) - 1,
IF( LOCATE('Bluray', title), LOCATE('Bluray', title) - 1,
IF( LOCATE('Series', title), LOCATE('Series', title) - 1,
IF( LOCATE('20 ', title), LOCATE('20 ', title) - 1,
999 )))))))))),
main_category,
genre,
actors
FROM
PRprodINFO
WHERE
((main_category = 'Films')
AND (length(title) > 2))
GROUP BY title
also tried:
SELECT
DISTINCT( TRIM( LEFT(title,
IF( LOCATE('10 Pack', title), LOCATE('10 Pack', title) - 1,
IF( LOCATE('100 Classic', title), LOCATE('100 Classic', title) - 1,
IF( LOCATE('100 Favourite', title), LOCATE('100 Favourite', title) - 1,
IF( LOCATE('DVD', title), LOCATE('DVD', title) - 1,
IF( LOCATE('Bluray', title), LOCATE('Bluray', title) - 1,
IF( LOCATE('Series', title), LOCATE('Series', title) - 1,
IF( LOCATE('20 ', title), LOCATE('20 ', title) - 1,
999 )))))))))),
main_category,
genre,
actors
FROM
PRprodINFO
where
((main_category = 'Films')
AND (title <> ''))
GROUP BY title
but still blank title field rows are returned...any ideas why?
Thanks
Darren
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果字段为
null
,则LOCATE(astr, field)
将返回 null。您需要确保
title
不为空。要么将
title
替换为COALESCE(title)
,要么执行以下操作:If a field is
null
thenLOCATE(astr, field)
will return null.You need to make sure
title
is not null.Either replace
title
withCOALESCE(title)
everywhere or do:我会将以下内容添加到您的 WHERE 子句中...
而不是您的“
如果您有任何 NULL 值,这些值将会丢弃它”,此外,如果标题的值为“”,那也可能会给出误报。因此,通过执行 NVL() (如果为空值,则使用 ''),然后修剪它,然后检查长度......您应该获得满足您需求的所有资格。
I would add the following to your WHERE clause...
instead of your
If you have any NULL values, those will throw it off, Additionally, if a title has a value of " ", that too could give false positive. So, by doing an NVL() (if null value, use the ''), then trimming that, then checking the length... you should get all qualified for your needs.
尝试修改大量
IF
块,以便在不满足任何条件时返回title
。结果如何?Try modifying your massive
IF
block so that it returnstitle
when none of the conditions are met. What are the results?