Skip to content

Instantly share code, notes, and snippets.

@alejandrobernardis
Created January 30, 2014 08:37
Show Gist options
  • Save alejandrobernardis/8704689 to your computer and use it in GitHub Desktop.
Save alejandrobernardis/8704689 to your computer and use it in GitHub Desktop.
Calculo depuntos
select distinct points.user_id as user_id, points.total-redeem.total as total
from (
select tickets.id_cliente as user_id, sum(tickets.puntos_obtenidos) as total
from tickets where aprobado=1 and cancelado=0 group by tickets.id_cliente
) points
left join (
select articulos_recibidos.id_cliente as user_id, sum(articulos_recibidos.puntos) as total
from articulos_recibidos group by articulos_recibidos.id_cliente
) redeem on redeem.user_id=points.user_id
order by user_id asc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment