简体   繁体   中英

Oracle SQL Subquery Error

I was trying to write a subquery to left join table, but I had error, need help to find out my mistake, thanks.

select IT.*,
(select  firstname,lastname,sum(cost) as 2016_cost,agencyname
from sheet1
group by firstname,lastname,agencyname as aa)
from IT
left join aa on IT.lastname=aa.lastname,IT.firstname=aa.lastname

It looks like you want this:

SELECT IT.*, aa.firstname, aa.lastname, aa.2016_cost, aa.agencyname
FROM IT
LEFT JOIN (SELECT firstname, lastname, sum(cost) as 2016_cost, agencyname
           FROM sheet1
           GROUP BY firstname, lastname, agencyname
          ) as aa on IT.lastname = aa.lastname
                 and IT.firstname = aa.lastname

The subquery in your code is in the SELECT , where you would put a column level subquery. You seem to want a table subquery, or derived table, which should go in your FROM/JOIN list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM