Kode
09-01-2014, 16:56
I have narrowed it down a bit I think:
incomplete:
SELECT movie_name, IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '10' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS movielogo,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '11' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS movieart,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '12' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS moviedisc,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '16' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS moviebackground,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '19' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS moviebanner,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '23' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS hdmovielogo,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '24' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS moviethumb,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '26' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS hdmovieclearart,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '29' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS movieposter FROM movie_items HAVING movielogo > 0 OR movieart > 0 OR moviedisc > 0 OR moviebackground > 0 OR moviebanner > 0 OR hdmovielogo > 0 OR moviethumb > 0 OR hdmovieclearart > 0 OR movieposter > 0
This works, and the coulmns and having sections are built with php, it returns a 0 if there are images, and a 1 in there are none, the idea was to SUM these and order by that, therefore the rows with the lowest number would be the most complete, however, you can't SUM aliases and not sure how to rearrange the query to do this, an easier to read example is:
this produces something like:
incomplete:
SELECT movie_name, IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '10' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS movielogo,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '11' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS movieart,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '12' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS moviedisc,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '16' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS moviebackground,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '19' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS moviebanner,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '23' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS hdmovielogo,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '24' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS moviethumb,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '26' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS hdmovieclearart,IF((SELECT COUNT(image_id) FROM movie_images WHERE image_active = 'y' AND image_type = '29' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS movieposter FROM movie_items HAVING movielogo > 0 OR movieart > 0 OR moviedisc > 0 OR moviebackground > 0 OR moviebanner > 0 OR hdmovielogo > 0 OR moviethumb > 0 OR hdmovieclearart > 0 OR movieposter > 0
This works, and the coulmns and having sections are built with php, it returns a 0 if there are images, and a 1 in there are none, the idea was to SUM these and order by that, therefore the rows with the lowest number would be the most complete, however, you can't SUM aliases and not sure how to rearrange the query to do this, an easier to read example is:
Code:
SELECT movie_name, IF((SELECT COUNT(image_id) AS images FROM movie_images WHERE image_active = 'y' AND image_type = '10' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS movielogo, IF((SELECT COUNT(image_id) AS images FROM movie_images WHERE image_active = 'y' AND image_type = '11' AND image_movie_tmdb_id = movie_tmdb_id) > 0, 0, 1) AS movieart FROM movie_items HAVING movielogo > 0 OR movieart > 0
Code:
movie_name movielogo movieart Harry Potter and the Goblet of Fire 0 1 Harry Potter and the Deathly Hallows: Part 1 0 1 Blade 0 1