简体   繁体   English

在不同的列中排列电影的标题

[英]Arrange the titles of the films in different columns

This query extracts此查询提取

  • 'id', actor's id 'id',演员的身份证
  • 'name', name of the actor 'name',演员的名字
  • 'image', image of the actor '形象',演员的形象
  • 'film', number of films in which there is the actor '电影',有演员的电影数量
  • 'title', title of the film 'title',电影的标题

from the database.从数据库。 db-fiddle db小提琴

Is it possible to make sure that the films are not all grouped in a single column, but grouped in two or more columns distinctly?是否可以确保电影不是全部归为一列,而是明确归为两列或更多列?

For example,例如,

actors id: 3, 1, 43 have two films in common but only one is displayed. actor id: 3, 1, 43 有两部电影共有,但只放映了一部。

It should be它应该是

  film 1 film 2
Exorcist-I, Exorcist-II

while the actor id: 7而演员id:7

  film 1 film 2
Exorcist-I null

and actor id: 42演员编号:42

  film 1 film 2
   null Exorcist-II

Thanks in advance for your help在此先感谢您的帮助

After some digging, and excluding your restrictions经过一番挖掘,排除了你的限制

SELECT  
  fa1.actor_id actor_id,
  a.name  name,
  a.act_img  actimg,
  Count(*) film,
  GROUP_cONCAT(DISTINCT f1.title ORDER BY f1.film_id) title
FROM
  (SELECT 
    film_id,actor_id 
  FROM film_actor
  WHERE film_id in (select film_id 
    from film_actor where actor_id = 1)
  ) fa1 
  inner join film f1 ON fa1.film_id = f1.Film_id
  inner join actor a ON fa1.actor_id = a.actor_id
GROUP BY actor_id,name,act_img
ORDEr by film DESC

Gives you following result给你以下结果

actor_id    name                        actimg             film     title                          
1           Linda Blair                 l_blair.jpg        2        Exorcist,Exorcist II: the Heretic
3           Max von Sydow               m_vsydow.jpg       2        Exorcist,Exorcist II: the Heretic
43          Kitty Winn                  k_winn.jpg         2        Exorcist,Exorcist II: the Heretic
5           William O'Malley            w_omalley.jpg      1        Exorcist                       
44          Paul Henreid                p_henreid.jpg      1        Exorcist II: the Heretic       
52          Robert Symonds              r_symonds.jpg      1        Exorcist                       
6           Lee J.Cob                   l_jcob.jpg         1        Exorcist                       
45          Dana Plato                  d_plato.jpg        1        Exorcist II: the Heretic       
53          Barton Heyman               b_heyman.jpg       1        Exorcist                       
7           Eileen Dietz                e_dietz.jpg        1        Exorcist                       
46          Ned Beatty                  n_beatty.jpg       1        Exorcist II: the Heretic       
54          Robert Schündler            r_schündler.jpg    1        Exorcist                       
8           Mercedes McCambridge        m_mcambridge.jpg   1        Exorcist                       
47          James Earl Jones            j_ejones.jpg       1        Exorcist II: the Heretic       
55          Arthur Storch               a_storch.jpg       1        Exorcist                       
9           Ron Faber                   r_faber.jpg        1        Exorcist                       
48          Belinda Beatty              b_beatty.jpg       1        Exorcist II: the Heretic       
56          Barbara Cason               b_cason.jpg        1        Exorcist II: the Heretic       
2           Ellen Burstyn               e_burstyn.jpg      1        Exorcist                       
41          Richard Burton              r_burton.jpg       1        Exorcist II: the Heretic       
49          Jack MacGowran              j_macgowran.jpg    1        Exorcist                       
57          Ken Renard                  k_renard.jpg       1        Exorcist II: the Heretic       
42          Louise Fletcher             l_fletcher.jpg     1        Exorcist II: the Heretic       
50          Thomas Bermingham           t_bermingham.jpg   1        Exorcist                       
58          Karen Knapp                 no_foto.png        1        Exorcist II: the Heretic       
4           Jason Miller                j_miller.jpg       1        Exorcist                       
51          Peter Masterson             p_masterson.jpg    1        Exorcist  

Which you can see working https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=eec13d233c5b46a4eec03988cb09be2f你可以看到工作https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=eec13d233c5b46a4eec03988cb09be2f

Your constraints don't work, because of different reasons, that's why i excluded them from the example.由于不同的原因,您的约束不起作用,这就是我将它们排除在示例之外的原因。 There are also missing tables.还有缺少的表。

I also has to eliminate '0000-00-00 00:00:00' and replace it with NULL for this example to work, because of the restrictions of the server.由于服务器的限制,我还必须消除 '0000-00-00 00:00:00' 并将其替换为 NULL 才能使此示例正常工作。 . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM