sql - oracle window functions -
could me out query:
select sum(summa), name, to_char(invoice_date, 'yyyy/mm') on (partiton extract(month i.invoice_date, c.name) invoice i, customer c i.customer_id = c.id , months_between(sysdate, invoice_date) = 3 , rownum < 11 group invoice_date, name order sum(summa) desc; supposed first ten rows last 3 months, grouped month , ordered sum.
thanks.
first, use proper explicit join syntax. second, need row_number():
select t.* (select sum(summa) sumsumma, name, to_char(invoice_date, 'yyyy/mm') yyyymm, row_number() on (partition to_char(invoice_date, 'yyyy/mm') order sum(summa) desc ) seqnum invoice join customer c on i.customer_id = c.id months_between(sysdate, invoice_date) = 3 group invoice_date, name ) t seqnum <= 10 order sumsumma desc;
Comments
Post a Comment