mysql - Pass variable into subquery -


i extract clients' offers each project and, in case have more 1 offer, average value.

i have following query:

select @projectid := projects.id projectid, (select   sum(`offers`)   (select avg( `price` ) `offers`     `sales`     `sales`.`projectid` = @projectid     , `sales`.`active` = 'yes'     group `sales`.`clientid`   ) `average` ) `outstanding` projects projects.active = 'yes' order outstanding asc  

my problem @projectid not passed subquery, , don't understand how should solve issue.

can please give me advices?

remember sql declarative language, not imperative one. many problem solved using join , subqueries without "variables". so...

... i'm not sure understand -- need "for each project sum of average offers each client", trick:

select s.projectid, sum(offers)   (     select projectid, clientid, avg(price) offers sales active = 'yes'     group projectid, clientid   ) s  join projects on s.projectid = projects.id , projects.active = "yes" group projectid 

see http://sqlfiddle.com/#!2/19d0f/24


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -