我正在尝试获取一些已经支付服务费用并在某一年内从mysql数据库注册的用户数量。会员可以支付多种服务费用,因此可以计算两次:
select
count(payment_order.memberId) as members,
from_unixtime(account_login.memberFrom, '%Y') as memberFrom
from
payment_order
join
account_login
on
payment_order.memberId = account_login.memberId
Where
account_login.memberFrom != '0'
and payment_order.`status` = 'paid'
and payment_order.dateCompleted >= '2010-01-01 00:00:00'
and payment_order.dateCompleted <= '2011-12-31 23:59:59'
group by memberFrom
它不是按年份分组,而是按个别成员计数进行分组。我想我正在做一些事情,可以看到木头的树木:
1, 2005
4, 2005
1, 2005
1, 2006
5, 2006
5, 2006
我正在寻找的是
6, 2005
11, 2006
感谢任何可能解释我迷惑的指示
答案 0 :(得分:6)
您按account_login.memberFrom
进行分组,这会创建每一行。
然后,您在每个行上选择from_unixtime(account_login.memberFrom, '%Y')
,创建重复值。
相反,请使用GROUP BY from_unixtime(account_login.memberFrom, '%Y')