我收到了错误:
“[Err] 1111 - 对此查询无效使用组功能”
SELECT u.date, u.des_channel, u.des_type,
count(distinct(u.id)),
sum(if(u.date=bp.date,sum(bp.o_outcome),0),
sum(if(u.date=bp.date,1,0)) as P_n,
count(distinct(if(u.date=bp.date,bp.user_id,0)))
FROM mayadata.users u
left join mayadata.billing_pays bp
on u.id=bp.user_id
WHERE (u.date)=5 and year(u.date)=2011 and truncate(monthtimestampdiff(hour,u.datetime,bp.datetime)/24,0)<7
GROUP BY u.date, u.des_channel, u.des_type
答案 0 :(得分:0)
您需要使用HAVING
SELECT u.date, u.des_channel, u.des_type,
COUNT(DISTINCT(u.id))
SUM(if(u.date = bp.date, SUM(bp.o_outcome),0)) SUM(if(u.date = bp.date,1,0)) AS P_n,
COUNT(DISTINCT(if(u.date = bp.date, bp.user_id,0)))
FROM mayadata.users u
LEFT JOIN mayadata.billing_pays bp ON u.id = bp.user_id
GROUP BY u.date, u.des_channel, u.des_type
HAVING (u.date) = 5
AND year(u.date) = 2011
AND truncate(monthtimestampdiff(hour,u.datetime,bp.datetime)/24,0)<7
答案 1 :(得分:0)
错误是由{/ 1}}
中的SUM
引起的
SUM
这是非法的