dimanche 22 mars 2015

Sql edit existing query to get other stuff from database

I currently have the following select statement which gives me total money spent in specific date, however, I would like to change it to also give me details such as customerid and customer_name. Customerid sits in Customer table, customer_name in User table, both tables are connected (FOREIGN_KEY)Customer.USERID -> User.CUSERID Also might be helpful:



(FOREIGN_KEY)PAYMENT.CUSTOMERID -> CUSTOMER.CUSTOMERID
(FOREIGN_KEY)PAYMENT.ORDERID -> ORDER.ORDERID
(FOREIGN_KEY)ORDER.CUSTOMERID -> CUSTOMER.CUSTOMERID


.



SELECT DISTINCT PAYMENT.CUSTOMERID,
SUM(DISTINCT PAYMENT.PAYMENT_AMOUNT) AS TOTAL_CUSTSPENT
FROM PAYMENT
JOIN Order ON PAYMENT.ORDERID = Order.ORDERID
WHERE MONTH(Order.ORDER_DATE) = SOME_MONTH AND YEAR(Order.ORDER_DATE) = SOME_YEAR GROUP BY PAYMENT.CUSTOMERID


Question is how can I change this statement to make it also getting customerid and customer_name?


Aucun commentaire:

Enregistrer un commentaire