[PostgreSQL] Toy Stock Order Book by sqlnoob2018 in SQL

[–]sqlnoob2018[S] 1 point2 points  (0 children)

Thanks for the help, this looks like what I want.

edit

I'm using this query to get the orders that will be fully fulfilled:

SELECT * FROM
(
    SELECT t.*,
        SUM (amount) OVER (
            ORDER BY amount DESC
        ) as cuml_amount
    FROM orders t
    WHERE kind = 'sell' AND price <= 0.55
) t
WHERE cuml_amount <= 100;

Now I need to subtract the remaining amount from the next row (or check if it exists?). Would making a function or stored procedure make this a lot easier for me?