试一下
select * from (
SELECT
DATE(FROM_UNIXTIME(a.date)) AS create_time,
b.id,
a.`user_id`,
a.`message`,
a.`comments`,
a.`likes`,
b.email,
b.`username` AS sentname,
case when a.`message` LIKE '%#今日心得与分享%' then '心得与分享' else '管理建议'end AS type
FROM
`users` b,
`posts` a
WHERE a.`user_id`=b.`id`
AND (a.`message` LIKE '#今日心得与分享%' OR a.`message` LIKE '#管理建议%')
AND date(from_unixtime(a.date))>='${starttime}'
and date(from_unixtime(a.date))<='${endtime}'
${if(len(sentname) == 0,""," and b.`username` in ('" + sentname+ "')")}
) t
where 1=1
${if(len(type) == 0,""," and type in ('" + type+ "')")}