SELECT (CREDITS.CRED_VALUE_PER_CREDIT-PACKAGE_DEFAULTS.PACDEF_TUTOR_HOURLY_PAY/LESSON_TYPES.LESTY_BILLING_PERSONS) *CREDITS.CRED_NUM_OF_CREDITS AS PROFIT,
YEAR(CREDITS.CRED_PURCHASE_DATE), MONTH(CREDITS.CRED_PURCHASE_DATE), CRED_ID
FROM CREDITS INNER JOIN CUSTOMERS ON CREDITS.CRED_CUS_ID = CUSTOMERS.CUS_ID INNER JOIN LESSON_TYPES ON CREDITS.CRED_LESTY_ID = LESSON_TYPES.LESTY_ID INNER JOIN PACKAGE_DEFAULTS ON LESSON_TYPES.LESTY_ID = PACKAGE_DEFAULTS.PACDEF_LESTY_ID
WHERE MONTH(CREDITS.CRED_PURCHASE_DATE) = '02' AND YEAR(CREDITS.CRED_PURCHASE_DATE) = '2010' AND CUSTOMERS.CUS_USER_ID = '14' AND CREDITS.CRED_DEACTIVE = 0 AND CREDITS.CRED_ORDER_STATUS = 4
GROUP BY PACDEF_TUTOR_HOURLY_PAY, CREDITS.CRED_VALUE_PER_CREDIT
|