alex
alex

Reputation: 4914

Mysql how to Count rows and group by value?

I am trying to get this simple query to work. I like to know how many times a certain vouchercode has been used and what the total discount value is per used voucher code.

The database table has fields discount_value, discount_data. The discount_data holds the vouchercode and discount_value the sum of discount per purchase id.

SELECT discount_data, 
       COUNT(*) 
  FROM wp_wpsc_purchase_logs 
GROUP BY 
       discount_data

seems to work to get amount of voucher code used.

But how do i get the total discount_value per used voucher code?

regards

Upvotes: 0

Views: 135

Answers (2)

G one
G one

Reputation: 2729

Sum() function may be

SELECT discount_data, SUM(discount_value), count(*)
FROM wp_wpsc_purchase_logs 
GROUP BY discount_data

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269773

Is the SUM() function what you are looking for?

SELECT discount_data, COUNT(*), SUM(discount_value)
FROM wp_wpsc_purchase_logs 
GROUP BY discount_data

Upvotes: 1

Related Questions