Mysql查询:需要累计每月给定的订单号[关闭]

I have this table in which the last two rows are month and year respectively

orders

where idalbaran is equivalent to an order number. Now, in another table I have the details of these orders, the table looks like this:

order_details

the last two rows are price and quantity

using mysql and php I need to obtain a list that looks like this:

enter image description here

This is the MySQL part:

SELECT 
    idcliente,
    mes AS month,
    anio AS year, 
    SUM(precio*candidad) AS totalSoldToThatClientThatMonth
FROM client_table CT
    JOIN orders_table OT
      ON CT.idalbaran = OT.idalbaran
GROUP BY idcliente, mes, anio

I assume the first table's name is client_table, and the second name is orders_table

Try this:

select ft.idcliente, ft.mes, ft.anio,
sum(st.precio*st.cantidad) as Total
from firsTable ft
inner join secondTable st
on (st.idalbaram = ft.idalbaran)
group by ft.idcliente, ft.mes,ft.anio