SELECT
COUNT( * ) AS c,
target_id
FROM
expend
WHERE
expense_type = 1
AND target_id IN ( SELECT id FROM user WHERE add_time >= UNIX_TIMESTAMP( "2019-06-29" ) AND add_time < UNIX_TIMESTAMP( "2019-06-30" ) AND user_id > 0 )
AND TIME < UNIX_TIMESTAMP( "2019-07-06" )
GROUP BY target_id
HAVING ( c > 10 AND c < 15 )
HAVING
这里就是HAVING多个字段的用法
GROUP BY target_id HAVING ( c > 10 AND c < 15 )
UNIX_TIMESTAMP('fromdata') 内置函数,将格式化的日期转化为时间戳
UNIX_TIMESTAMP('2019-06-29') == 1561737600
FROM_UNIXTIME(1561737600,'%Y-%m-%d') == '2019-06-29'