SELECT
*,
format((money / userC), 1) messageAp,
format((customMoney / userC), 1) customAp,
format((userMoney / userC), 1) userAp
FROM
(
SELECT
*, format(
money * (customSlice / 100) - money * ((1 - kLslice / 100) *(slice / 100)),
2
) returnMoney,
format(money *(customSlice / 100), 2) customMoney,
format(
money * ((1 - kLslice / 100) *(slice / 100)),
2
) userMoney
FROM
(
SELECT * , (
SELECT
count(1)
FROM
activation
WHERE
`dateTime` = '2018-11-12'
AND channel = channela
) userC
from (
SELECT
der.kLslice,
der.userSlice slice,
der.productId,
der.money,
po.fbName productName,
der.slice customSlice,
der.appId appId,
der.channel channela,
der.orderTime dataTime,
der.sdk sdkN,
cus.sdkCustom
FROM
cus_sdk cussdk
LEFT JOIN custom cus ON cus.id = cussdk.customId
LEFT JOIN `order` der ON cussdk.sdkNum = der.sdk
LEFT JOIN product po ON po.id = der.productId
where
der.orderTime = '2018-11-12' and der.onLine_channel_order = 0
GROUP BY
der.orderTime,
der.appId,
der.channel,
der.sdk,
der.slice
) cc
) dd
) ss