select aud.realname as `realName`,aud.nickname as `nickName`,aul.username as `phone`,aupt.position_id as `postionId`,aupt.company_id as `companyId`,aupt.company_name as `companyName`
from `app_user_detail` as `aud` left join `app_user_login` as `aul`
on aul.id=aud.userid left join `app_user_position_temp` as `aupt`
on aupt.user_id=aul.id left join `app_user_position` as `aup`
( IFNULL(auswu.upIncome,0) - IFNULL(auswd.dowIncome,0) ) AS `income`
FROM
( SELECT IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` WHERE STATUS = 0 AND `user_id` = #{userId} ) AS `auswu`,
( SELECT IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` WHERE STATUS = 1 AND `user_id` = #{userId} ) AS `auswd`;
( SELECT IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` WHERE STATUS = 0 AND waiting=1 AND `user_id` = #{userId} ) AS `auswu`,
( SELECT IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` WHERE STATUS = 1 AND waiting=1 AND `user_id` = #{userId} ) AS `auswd`;
`auswu`.user_id, ( IFNULL(auswu.upIncome,0) - IFNULL(auswd.dowIncome,0) ) AS `commission`
FROM
( SELECT `user_id` as `userId`, IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` where STATUS = 0 and waiting=1 <iftest="userIds!=null and userIds.size!=0">
AND `user_id` IN <foreachcollection="userIds"item="userId"open="("close=")"separator=",">
#{userId}
</foreach>
</if> group by user_id) AS `auswu`
left join
( SELECT `user_id`,IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` where STATUS = 1 and waiting=1 <iftest="userIds!=null and userIds.size!=0">
AND `user_id` IN <foreachcollection="userIds"item="userId"open="("close=")"separator=",">