mysql - SQL Query - ORDER BY -
rs.open "select [a$].security,[a$].name,sum([a$].[price]) [a$] inner join [b$] on [a$].security = [b$].id group [a$].security,[a$].description", cn, adopenkeyset, adlockreadonly
the result query not align or match respective id in sheet b. example :- master worksheet aggregate records matching id of b , security of a. now, might have multiple instances of b's id having different price, reason why aggregate. question when paste record set data, see aggregated price value not pasted in front of id in b i.e want them ordered according id in b , order doesn't work, throwing error [b$].id not part of aggregate function. can hint on how can done ?
try instead:
rs.open "select [b$].id, [a$].name, sum([a$].[price]) [b$] left join [a$] on [b$].id = [a$].security group [b$].id, [a$].name", cn, adopenkeyset, adlockreadonly
this should give total price each id in b , include ids b have no entries in a. every non-aggregated column in select clause has appear in group clause because selecting id , name, both of in group clause. if there multiple names same id won't work correctly you'll multiple lines per id.
maintaining same order entries in b isn't possible unless either sort b natural sort order ado uses or add additional column b use in order clause
Comments
Post a Comment