我写了两个mysql查询,其中一个提取我在一年的特定月份中出现的总用户(注册),另一个提取当年特定月份中的活动用户。我需要找到当年不活跃用户的数量。为此,我正在考虑减去通过两个单独查询获得的totalUsers和activeUsers列。 下面是查询在Mysql中减去两个Select查询的结果
1. Fetch Total Registered users
set @numberOfUsers := 0;
SELECT T.createdMonth, T.monthlyusers, (@numberOfUsers := @numberOfUsers + T.monthlyusers) as totalUsers
FROM
(
SELECT month(from_unixtime(u.createdDate)) as createdMonth, count(u.id) as monthlyusers
FROM user u
where year(from_unixtime(u.createdDate)) = '2016'
group by month(from_unixtime(u.createdDate))
) T;
2. Fetch Active Users
select month(from_unixtime(lastActive)), (count(u.id)) as activeUsers from user u
where year(from_unixtime(lastActive)) = '2016'
group by month(from_unixtime(lastActive));
我需要从totalUsers减去activeUsers。我如何实现这一目标?
发现一个StackOverflow的答案,回答是[这里](http://stackoverflow.com/questions/6715095/how-to-sum-and-subtract - 使用-SQL)。 – IAMZERG