mysql - Combine data from 2 "strange" tables -
having following schema
(er of database) trying create query
will show title(
movies
.title
) along each movie's genre(movie_genres
.movie_genre
) each movie that..that have been seen in (a) specific time period (lets 2-3 days ex. can take days
tickets
.ticket_date
) (b) male customers(customer
.customer_sec
) , (c) got rated more 4 (rated_customerration) customers.
i can close following query:
select `movie_title`, `movie_genres`.`movie_genre` `movies` inner join `movie_genres` on `mg_movie` = `movie_id` inner join `rated` on `rated_movie_id` = `movie_id` `rated_customerratio` > 4 , union (select `customer_sex`, `rated_customerratio` `customer` /* inner join `cinema`.`rated` on `rated`.`rated_customer_tabid` = `customer`.`customer_tabid` */ inner join `cinema`.`tickets` on `tickets`.`ticket_customer_tabid`=`customer`.`customer_tabid` `customer_sex` 'male' /* , rated_customerratio > 4 */ , `tickets`.`ticket_date` > '2016-02-16') group `movie_title`;
also thinking have trouble, cause 1 movie can have more 1 genre, , don't want double lines, same movie, in outcome.
any taken serious regards!
use where movie.id in (select movie.id...)
query have unusual query relationships. i.e. if movie.id can related tickets
where movieid in ( select movieid movietable left join tickets on movieid = tickets.movieid left join customer on tickets.id = customer.id customer.customer_sex 'male' , tickets.ticket_date > '2016-02-16') )
i dont know db schema should give rough idea on 1 way of sorting based on viewership of moves tickets? 1 ticket should have 1 movie id , 1 customer, relationship pretty easy figure out
Comments
Post a Comment