sql - How can i use two fields in a SELECT clause that has a "single-group group function" -
i need write query joins lot of queries. connected id. problem in 1 of queries, value have select "single-group group function" , must evaluate condition on on
clause must use second selected column, i'm unable add. i'll write lot easier example code:
select frst.firstresult, scnd.firstresult from( select firstresult, id_to_compare secondresult table -- [...] ) frst join( select firstresult, id_to_compare secondresult table2 -- [...] ) scnd on frst.secondresult=scnd.secondresult join( select firstresult, id_to_compare secondresult table3 -- [...] ) trd on scnd.secondresult=trd.secondresult -- [...] join( select single_group_function(params) firstresult, id_to_compare secondresult table3 --this select cannot done because of group function cannot executed -- [...] ) trd on svn.secondresult=eit.secondresult
my problem need compare "secondresult" every select, member group not allowed make query this. i've tried "dual" table it's messy me , don't understand how use it. i've tried joining them in macro query, every single select big enough confusing write. i've taken ideas this post , lot more. have hint acomplish task?
for petition of mt0, minimal complete , verificable problem this:
select frst.firstfield, scnd.firstfield, frst.secondfield (select a1.dummy firstfield, a2.dummy secondfield dual a1 join dual a2 on 1=1) frst join (select a1.dummy firstfield, a2.dummy secondfield dual a1 join dual a2 on 1=1) scnd on frst.secondfield = scnd.secondfield join (select sum(a1.dummy) firstfield, a2.dummy secondfield dual a1 join dual a2 on 1=1) trd on trd.secondfield = scnd.secondfield ;
i expect in case
frst.firstfield scnd.firstfield frst.secondfield ---------------- ---------------- -------------------- x x 1
but instead
error en la línea de comandos : 11 columna : 40 informe de error - error sql: ora-00937: la función de grupo no es de grupo único 00937. 00000 - "not single-group group function" *cause: *action:
this sample subquery:
select sum(a1.dummy) firstfield, a2.dummy secondfield dual a1 join dual a2 on 1=1
so expect 1 result row? aggregation no group by
does. you'd sum on records, a2.dummy
show in result record? dbms complaining about.
what want sum per a2.dummy
instead. group column:
select sum(a1.dummy) firstfield, a2.dummy secondfield dual a1 join dual a2 on 1=1 group a2.dummy
Comments
Post a Comment