Skip to content

You can help with some complex querys? #1

@MythodeaLoL

Description

@MythodeaLoL

Hello, it's been a few days since I've been studying the project and the tables hard.

But I'm having difficulties to make some queries, I would like to know if you could help, if so, could you give more details.

An example of what I was trying to do is:
Search for a name in a title titles.original_title + titles.start_year
so far so good, I can pull the title info without problems.

But when I try to pull the complete cast, and relate it to the professions, ordering by the number of episodes that each actor has in the title, I can't. The query is always limited to a few actors.

I was using groupers like this to organize multiple results from an actor to a row
GROUP_CONCAT(DISTINCT had_role.role_ order by ifnull(principals.ordering,9999)) as role_
for the query of actors by title, I should be able to show

title_id, name_id, name, principal_role, role_, profession, episodes(COUNT)

I tried several variants of this, but without a base it was complicated because we have: table of professions, names, character and the titles itself to relate.

with a more complex base maybe I can make the other queries, until then I'll keep trying and if I can post it here in case no one has a solution.

some queries of the many I tried.

SELECT DISTINCT
#*,
peoples.name_id, peoples.name_ AS name, 
GROUP_CONCAT(DISTINCT papel.role_ order by ifnull(cast.ordering,9999)) as role_, # query 100%
worked.profession, peoples.birth_year, peoples.death_year 

FROM names_ AS peoples
   left JOIN had_role papel on papel.name_id = peoples.name_id
   left JOIN principals cast on cast.name_id = peoples.name_id
            #INNER JOIN names_ AS names ON names.name_id=hr.name_id
            left JOIN name_worked_as worked ON worked.name_id = peoples.name_id
            WHERE papel.title_id = 'tt0460681' 
            GROUP BY papel.name_id
SELECT DISTINCT  *
#JSON_ARRAY(GROUP_CONCAT( DISTINCT JSON_OBJECT( COALESCE(A.region, 'LOCAL'),   A.title))) as 'region', 
#T.runtime_minutes as 'runtime',
#T.start_year as 'start_year',
#T.end_year as 'end_year'
#JSON_ARRAY(GROUP_CONCAT( DISTINCT JSON_OBJECT( N.name_,   H.role_))) as 'casting',
#JSON_ARRAY(GROUP_CONCAT( DISTINCT JSON_OBJECT(G.genre, H.role_))) as 'genres',
#JSON_ARRAY(GROUP_CONCAT( DISTINCT JSON_QUOTE( '' ))) as 'writers',
#GROUP_CONCAT( DISTINCT N.name_) as 'genres2'

/*, T.primary_title, T.original_title, T.runtime_minutes, A.is_original_title*/
FROM titles AS T
, name_worked_as AS Name_Work
#, writers AS W
#, directors as D
#, known_for as K
, principals AS P
WHERE T.original_title = 'Supernatural' /*collate utf8mb4_general_ci*/
#AND T.title_id = G.title_id
#AND T.title_id = A.title_id
#AND P.name_id  = N.name_id
#AND T.title_id = H.title_id
#AND T.title_id = W.title_id
#AND T.title_id = D.title_id
/*AND T.title_id = K.title_id*/

AND T.runtime_minutes <= 45 + 2
AND T.runtime_minutes >= 45 - 2
AND T.start_year = ('2005' +0)
/*AND A.region LIKE 'BR'*/
;

a mess no? many unsuccessful days give this.
@dlwhittenbury
if you need access to a db I can provide, just leave me your email and I'll send you the login.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions