此查询仍然返回空标题字段?

发布于 2024-12-11 14:57:20 字数 1463 浏览 0 评论 0原文

这个查询工作完美,除了它仍然返回空白标题字段:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

地狱即天堂 2024-12-18 14:57:20

如果字段为 null,则 LOCATE(astr, field) 将返回 null。
您需要确保 title 不为空。
要么将 title 替换为 COALESCE(title) ,要么执行以下操作:

SELECT DISTINCT( TRIM( LEFT(i.title, 
  IF( LOCATE('10 Pack', i.title), LOCATE('10 Pack', i.title) - 1, 
  IF( LOCATE('100 Classic', i.title), LOCATE('100 Classic', i.title) - 1, 
  IF( LOCATE('100 Favourite', i.title), LOCATE('100 Favourite', i.title) - 1, 
  IF( LOCATE('DVD', i.title), LOCATE('DVD', i.title) - 1,
  IF( LOCATE('Bluray', i.title), LOCATE('Bluray', i.title) - 1,
  IF( LOCATE('Series', i.title), LOCATE('Series', i.title) - 1,
  IF( LOCATE('20 ', i.title), LOCATE('20 ', i.title) - 1,999 ))))))))))
  , i.main_category, i.genre, i.actors 
FROM (SELECT main_category, genre, actors, COALESCE(title,'') as title 
      FROM PRprodINFO) i 
WHERE ((i.main_category = 'Films') AND (length(i.title) > 2)) 
GROUP BY i.title

If a field is null then LOCATE(astr, field) will return null.
You need to make sure title is not null.
Either replace title with COALESCE(title) everywhere or do:

SELECT DISTINCT( TRIM( LEFT(i.title, 
  IF( LOCATE('10 Pack', i.title), LOCATE('10 Pack', i.title) - 1, 
  IF( LOCATE('100 Classic', i.title), LOCATE('100 Classic', i.title) - 1, 
  IF( LOCATE('100 Favourite', i.title), LOCATE('100 Favourite', i.title) - 1, 
  IF( LOCATE('DVD', i.title), LOCATE('DVD', i.title) - 1,
  IF( LOCATE('Bluray', i.title), LOCATE('Bluray', i.title) - 1,
  IF( LOCATE('Series', i.title), LOCATE('Series', i.title) - 1,
  IF( LOCATE('20 ', i.title), LOCATE('20 ', i.title) - 1,999 ))))))))))
  , i.main_category, i.genre, i.actors 
FROM (SELECT main_category, genre, actors, COALESCE(title,'') as title 
      FROM PRprodINFO) i 
WHERE ((i.main_category = 'Films') AND (length(i.title) > 2)) 
GROUP BY i.title
寻找一个思念的角度 2024-12-18 14:57:20

我会将以下内容添加到您的 WHERE 子句中...

AND Length( TRIM( NVL(title, '' ))) > 2

而不是您的“

AND (title <> '' )

如果您有任何 NULL 值,这些值将会丢弃它”,此外,如果标题的值为“”,那也可能会给出误报。因此,通过执行 NVL() (如果为空值,则使用 ''),然后修剪它,然后检查长度......您应该获得满足您需求的所有资格。

I would add the following to your WHERE clause...

AND Length( TRIM( NVL(title, '' ))) > 2

instead of your

AND (title <> '' )

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.

原谅我要高飞 2024-12-18 14:57:20

尝试修改大量 IF 块,以便在不满足任何条件时返回 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 )))))), title )))),
    main_category, 
    genre, 
    actors
FROM
    PRprodINFO
where 
    ((main_category = 'Films')
    AND (title <> ''))
GROUP BY title

Try modifying your massive IF block so that it returns title when none of the conditions are met. What are the results?

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 )))))), title )))),
    main_category, 
    genre, 
    actors
FROM
    PRprodINFO
where 
    ((main_category = 'Films')
    AND (title <> ''))
GROUP BY title
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文