oracle窗口函数

时间:2015-05-11 17:25:19

标签: sql oracle window-functions

有人可以帮我解决这个问题:

SELECT SUM(summa), name, 
       TO_CHAR(invoice_date, 'YYYY/mm') 
           OVER (PARTITON EXTRACT(MONTH FROM i.invoice_date, c.name) 
FROM invoice i, customer c 
WHERE i.customer_id = c.id
AND months_between(sysdate, invoice_date) = 3
AND rownum < 11 GROUP BY invoice_date, name
ORDER BY SUM(SUMMA) DESC;

假设获得过去三个月的前十行,按月分组并按总和排序。

感谢。

1 个答案:

答案 0 :(得分:1)

首先,使用正确的显式import pyodbc my_cmd = """-- Comment's device INSERT INTO Example (id) VALUES (?) """ my_cmd_with_two_quotes = """-- Comment's device's INSERT INTO Example (id) VALUES (?) """ conn = pyodbc.connect("DSN=Abcdef;PWD=...") thing_named_cursor = conn.cursor() # success, replacing the single apostrophe: thing_named_cursor.execute(my_cmd.replace("'", "*"), (123, )) # success, too: thing_named_cursor.execute(my_cmd_with_two_quotes, (456, )) # failure: try: thing_named_cursor.execute(my_cmd, (789, )) except pyodbc.Error, e: print("Error: %s" % e) conn.commit() conn.close() 语法。其次,您需要join

row_number()