두 개의 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을 뺄 필요로하는 쿼리입니다. 어떻게 이것을 달성합니까?
가 응답하는 유래 응답이 [여기] (http://stackoverflow.com/questions/6715095/how-to-sum-and-subtract 발견이 쿼리를 빼거나 병합 할 수 있습니다 -using-sql). – IAMZERG