score:1

Accepted answer

this sql query is not correct, as you should bring what you have in select clause in group by clause (unless you use it in an aggregation function), so here you should use i.porcentaje in group by, although i do not think grouping by something like percentage is what you want.

i guess you want to sum all the total_linea considering porcentaje, so, for example, you can write your query as this:

you have joined tables correctly, after joining, because you only need id_iva and total_linea and porcentaje, gather only these values in an anonymous type, then group them by id_iva (as you did yourself), then choose values in your groupings and do your calculations:

var result = from l in linea_ventas
    join i in ivas on l.id_iva equals i.id_iva
    select new {
                 l.id_iva,
                 value = l.total_linea * i.porcentaje / 100
               } into selected
    group selected by selected.id_iva into groups
    select groups.sum(v => v.value);

Related Query

More Query from same tag