Dostaję na to zapytanie błąd: Every derived table must have its own alias
Czy ktoś coś widzi?
select U.`Name`,U.`Surname`,if(U.`Sex`,'Pani','Pan') ChSex,if(U.`Sex`,'Pani','Panie') CallSex,U.`Email`,
(
select
group_concat(
concat(
(
select group_concat(concat(RL.`Surname`,' ',RL.`Name`) separator ', ')
from `rpt_authors` RA,`rpt_aliases` RL
where
true
and RA.`ReportId`=R.`Id`
and RL.`Id`=RA.`AliasId`
group by RA.`ReportId`
order by RL.`Surname`<>L.`Surname`,RL.`Surname`
),
': ',
R.`Title`,', ',
R.`Number`,', ',
R.`Year`
)
separator '\r'
)
from
`rpt_reports` R,`rpt_authors` A,`rpt_aliases` L
where
true
and L.`UserId`=U.`Id`
and A.`AliasId`=L.`Id`
and R.`Id`=A.`ReportId`
and U.`Id` in
(
select
`UserId`
from
(
select
count(A1.`ReportId`) Cnt,L1.`UserId`
from
`rpt_authors` A1,`rpt_aliases` L1
where
L1.`UserId` in
(
select
L2.`UserId`
from
`rpt_authors` A2,`rpt_aliases` L2
where
A2.`ReportId`=A.`ReportId`
)
and A1.`AliasId`=L1.`Id`
and (select count(A3.`AliasId`) from `rpt_authors` A3 where A3.`ReportId`=A1.`ReportId`)>1
group by L1.`UserId`
order by Cnt desc
)
limit 1
)
group by L.`UserId`
) Reports,
(
select
min(R.`Year`)
from
`rpt_reports` R,`rpt_authors` A,`rpt_aliases` L
where
true
and L.`UserId`=U.`Id`
and A.`AliasId`=L.`Id`
and R.`Id`=A.`ReportId`
and U.`Id` in
(
select
`UserId`
from
(
select
count(A1.`ReportId`) Cnt,L1.`UserId`
from
`rpt_authors` A1,`rpt_aliases` L1
where
L1.`UserId` in
(
select
L2.`UserId`
from
`rpt_authors` A2,`rpt_aliases` L2
where
A2.`ReportId`=A.`ReportId`
)
and A1.`AliasId`=L1.`Id`
and (select count(A3.`AliasId`) from `rpt_authors` A3 where A3.`ReportId`=A1.`ReportId`)>1
group by L1.`UserId`
order by Cnt desc
)
limit 1
)
group by L.`UserId`
) MinYear,
(
select
max(R.`Year`)
from
`rpt_reports` R,`rpt_authors` A,`rpt_aliases` L
where
true
and L.`UserId`=U.`Id`
and A.`AliasId`=L.`Id`
and R.`Id`=A.`ReportId`
and U.`Id` in
(
select
`UserId`
from
(
select
count(A1.`ReportId`) Cnt,L1.`UserId`
from
`rpt_authors` A1,`rpt_aliases` L1
where
L1.`UserId` in
(
select
L2.`UserId`
from
`rpt_authors` A2,`rpt_aliases` L2
where
A2.`ReportId`=A.`ReportId`
)
and A1.`AliasId`=L1.`Id`
and (select count(A3.`AliasId`) from `rpt_authors` A3 where A3.`ReportId`=A1.`ReportId`)>1
group by L1.`UserId`
order by Cnt desc
)
limit 1
)
group by L.`UserId`
) MaxYear
from `rpt_users` U
where
true
;
CREATE TABLE `rpt_users` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Sex` tinyint(1) unsigned DEFAULT NULL,
`Birthday` int(11) DEFAULT '0',
`LanguageId` int(11) DEFAULT NULL,
`Title` tinytext CHARACTER SET utf8,
`Name` char(64) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
`Surname` char(64) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
`Adres` tinytext CHARACTER SET utf8,
`City` tinytext CHARACTER SET utf8,
`Postal` tinytext CHARACTER SET utf8,
`WhereIs` tinyint(1) unsigned NOT NULL DEFAULT '0',
`Email` tinytext CHARACTER SET utf8,
`Phone` tinytext CHARACTER SET utf8,
`Domains` mediumtext CHARACTER SET utf8,
`Links` mediumtext CHARACTER SET utf8,
`Info` mediumtext CHARACTER SET utf8,
...
CREATE TABLE `rpt_aliases` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`UserId` int(11) NOT NULL,
`Name` char(64) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
`Surname` char(64) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
...
CREATE TABLE `rpt_reports` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Number` char(16) CHARACTER SET utf8 NOT NULL,
`LanguageId` int(11) DEFAULT NULL,
`Title` mediumtext CHARACTER SET utf8,
`Year` int(11) NOT NULL,
...
CREATE TABLE `rpt_authors` (
`ReportId` int(11) NOT NULL,
`AliasId` int(11) NOT NULL
...