[英]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
. 数据库表具有字段discount_value
, discount_data
。 The discount_data
holds the vouchercode and discount_value
the sum of discount per purchase id. 该discount_data
持有vouchercode和discount_value
元购机优惠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 问候
Is the SUM()
function what you are looking for? 您正在寻找SUM()
函数吗?
SELECT discount_data, COUNT(*), SUM(discount_value)
FROM wp_wpsc_purchase_logs
GROUP BY discount_data
Sum() function may be Sum()函数可能是
SELECT discount_data, SUM(discount_value), count(*)
FROM wp_wpsc_purchase_logs
GROUP BY discount_data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.