我正在使用 SQL 访问实体(Forslag),但也想使用另一个实体的列(b.dato)进行排序。
这是我的初始 SQL:
select distinct ff.*
from Forslag ff
inner join Forlag f on ff.forlag_id = f.forlag_id
inner join LoggBehandling b on ff.forlag_id = b.forlag_id
inner join Kontrollpanel p on f.uhrPuMote_id = p.saksbehandlerUhrPuMote_id
where b.status_id = 7
union all
select distinct ft.*
from Forslag ft
inner join Tidsskrift t on ft.tidsskrift_id = t.tidsskrift_id
inner join LoggBehandling b on ft.tidsskrift_id = b.tidsskrift_id
inner join Kontrollpanel p on t.uhrPuMote_id = p.saksbehandlerUhrPuMote_id
where b.status_id = 7
order by b.dato desc
休眠抱怨:ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.
我怀疑我不能真正添加b.dato
到选择中,因为我认为这会对映射产生影响:
select distinct ff.*, b.dato
from Forslag ff
inner join Forlag f on ff.forlag_id = f.forlag_id
inner join LoggBehandling b on ff.forlag_id = b.forlag_id
inner join Kontrollpanel p on f.uhrPuMote_id = p.saksbehandlerUhrPuMote_id
where b.status_id = 7
union all
select distinct ft.*, b.dato
from Forslag ft
inner join Tidsskrift t on ft.tidsskrift_id = t.tidsskrift_id
inner join LoggBehandling b on ft.tidsskrift_id = b.tidsskrift_id
inner join Kontrollpanel p on t.uhrPuMote_id = p.saksbehandlerUhrPuMote_id
where b.status_id = 7
order by b.dato desc
我应该如何解决这个问题?