Created
January 30, 2014 08:37
-
-
Save alejandrobernardis/8704689 to your computer and use it in GitHub Desktop.
Calculo depuntos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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