我有一个问题:
SELECT Strtbmovie.id_parent,
Strtbuser.Name as 'Name',
Strtbmovie.Name as Movie,
sum(Strtbmovieatt.CountBeginWatch),
sum(Strtbmovieatt.CountEndWatch),
sum(Strtbmovieatt.CountBeginTest),
sum(Strtbmovieatt.CountEndTest),
max(Strtbmovieatt.CountTest)
FROM Strtbmovie
INNER JOIN Strtbmovieatt
ON Strtbmovie.Idmovie = Strtbmovieatt.Idmovie
INNER JOIN Strtbuser
ON Strtbmovieatt.Iduser = Strtbuser.Iduser
GROUP BY Strtbmovie.Name,
Strtbuser.Name,
Strtbmovie.id_parent
如何在知名id_parent?
的名称中替换此查询列id_parent答案 0 :(得分:3)
您必须使用Strtbmovie表INNER JOIN
添加额外的ON Strtbmovie.id_parent = StrtbmovieParent.Idmovie
,并按实际名称添加组,如下所示:
SELECT StrtbmovieParent.Name as ParentName,
Strtbuser.Name as 'Name',
Strtbmovie.Name as Movie,
sum(Strtbmovieatt.CountBeginWatch),
sum(Strtbmovieatt.CountEndWatch),
sum(Strtbmovieatt.CountBeginTest),
sum(Strtbmovieatt.CountEndTest),
max(Strtbmovieatt.CountTest)
FROM Strtbmovie
INNER JOIN Strtbmovieatt
ON Strtbmovie.Idmovie = Strtbmovieatt.Idmovie
INNER JOIN Strtbuser
ON Strtbmovieatt.Iduser = Strtbuser.Iduser
INNER JOIN Strtbmovie as StrtbmovieParent
ON Strtbmovie.id_parent = StrtbmovieParent.Idmovie
GROUP BY Strtbmovie.Name,
Strtbuser.Name,
StrtbmovieParent.Name