我很陌生SQL
,我一生都无法弄清楚为什么我不能做我在这里尝试的事情。我正在尝试在一次旅行中获得最少数量的免费座位,并按包裹 ID 对它们进行分组。
第一个子查询有效,但第二个是我无法弄清楚的。它说
'where 子句' 中的未知列 SuperPaket。
select Paket.PaketID as "SuperPaket", Beskrivning, Resa.AvgångStad, Resa.AvgångTid, Resa.AvgångDatum,
(select AnkomstTid from Resa where Resa.ResID in
(select ResID from PaketResa where PaketResa.PaketID = SuperPaket and Ordningsnr =
(select max(Ordningsnr) from PaketResa where PaketResa.PaketID = SuperPaket))) "AnkomstTid",
(select min(LedigaPlatser) from
(select sum(AntalPlatser - Count) "LedigaPlatser", ResID from(
select Bokning.ResID, AntalPlatser, sum(Bokning.AntalBiljetter) as Count from
(Resa inner join Bokning on Resa.ResID = Bokning.ResID) where Bokning.ResID in
(select PaketResa.ResID from PaketResa where PaketResa.PaketID = SuperPaket)
group by Bokning.ResID order by Count desc)
as CountTable group by ResID)
as T) "LedigaPlatser"
from ((Paket inner join PaketResa on Paket.PaketID = PaketResa.PaketID) inner join Resa on PaketResa.ResID = Resa.ResID) group by Paket.PaketID;
为什么这对第一个子查询有效,而对第二个子查询无效?
更新.. 当我在 from 子句中放置“子子查询”时,似乎出现了错误。我不知道如何重写有问题的查询来解决这个问题,我真的很感激一些帮助。谢谢..