好的,手头的任务是
获取已分发展览的奖品总和,直至2017年8月31日,收集和照片。我们认为这些奖项从未被遗弃过。
我的代码或多或少是
select t1.exhibitions, t2.exhibitions
from (
select exhibitions.premioc
from exhibitions
where EXISTS (select exhibitions.priceC
from exhibitions
join presentCo on exhibitions.id_e = presentCo.id_e
where presentaco.premiada > 0
group by exhibitions.priceC
)
) as t1
left outer join (select exhibitions
from exhibitions
where EXISTS (select exhibitions.priceF
from exhibitions
join presentFo on exhibitions.id_e = presentFo.id_e
where presentafo.preiceC > 0
group by exhibitions.priceF
)
) as "t2"
on t1.exhibitions= t2.exhibitions;
我的问题是,我有点不知道SQL中的语法,并且在交付前的最后一刻(学校作业)摸索。我试图搜索并让事情发挥作用,但我不知道我对这部分做错了什么。任何指针都很棒。非常感谢你的任何事情
编辑:当我发布它的时候已经深夜了,我从来没有提到真正的问题,我得到了SQL错误:ORA-00933:SQL命令没有正确结束而且没有真正理解。
答案 0 :(得分:0)
有:
查询看起来像这样:
select sum(prize_money)
from exhibitions
where exhibition_date < '2017-09-01'
我怀疑答案比你第一次想到的要简单得多
我现有的查询有几个问题,我看到了:
select t1.exhibitions -- this column is not returned by subquery t1 , t2.exhibitions from ( select exhibitions.premioc -- only this column is returned by subquery t1 from exhibitions where EXISTS -- when using EXISTS you need a "correlation" inside the where clause of the subquery (select exhibitions.priceC from exhibitions join presentCo on exhibitions.id_e = presentCo.id_e where presentaco.premiada > 0 -- there is NO "correlation" here group by exhibitions.priceC ) ) as t1 left outer join (select exhibitions from exhibitions where EXISTS ( -- when using EXISTS you need a "correlation" inside the where clause of the subquery select exhibitions.priceF from exhibitions join presentFo on exhibitions.id_e = presentFo.id_e where presentafo.preiceC > 0 -- there is NO "correlation" here group by exhibitions.priceF ) ) as "t2" on t1.exhibitions= t2.exhibitions;
我建议您需要开始新的,也许以此为起点?
SELECT
exhibitions.id_e
, COALESCE(c.prize_c, 0) prize_c
, COALESCE(f.prize_f, 0) prize_f
FROM exhibitions
LEFT JOIN (
SELECT
presentCo.id_e
, SUM(prize) prize_c
FROM presentCo
GROUP BY
presentCo.id_e
) AS c ON exhibitions.id_e = c.id_e
LEFT JOIN (
SELECT
presentFo.id_e
, SUM(proze) price_f
FROM presentFo
GROUP BY
presentFo.id_e
) AS f ON exhibitions.id_e = presentFo.id_e
但我不会尝试进一步的建议,除非我看到&#34;样本数据&#34; (对于每个表)和&#34;预期结果&#34;