1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] SQL Inner join query with a VWAP calculation

Discussão em 'Outras Linguagens' iniciado por Stack, Novembro 9, 2024 às 22:52.

  1. Stack

    Stack Membro Participativo

    I have 2 tables
    An orders table and Order QTY table
    [Order Prices Table][1] [Order Quantity Table ][2]
    I'm trying to create a query that calculates the volume weighted average price for a particular date, eg 2023-01-01. The formula for volume weighted average price is sum( order_price * order_qty ) / sum(order_qty)
    I've started the query with an inner join as price and qty have to be in the data set to work out the calculation.
    ...

    Select * From Order_Prices INNER JOIN Orders ON Order_Prices.OrderID = Order_Quantity.OrderID;

    ...
    I want to add order quantity to my data set as well (which resides in the order quantity table, (not sure how to do this) and how to insert the formula for volume weighted average.
    Any help would be appreciated.
    [1]: https://i.sstatic.net/M69U7oBp.png [2]: https://i.sstatic.net/phL2ywfg.png

    Continue reading...

Compartilhe esta Página