Every derived table must have its own alias(MySQL报错:每个派生表都必须有自己的别名)
当有子查询时,需要为每个子查询的记录起一个别名。
即 select * from (select a,b,c from d)as t1
总之,起个别名就好了
附一段生产sql
SELECT * FROM
(select base.id,
base.member_id,
(date_format(base.plan_date,'%Y%m%d') - date_format(now(), '%Y%m%d')) as expireDay,
base.plan_date as planDate,
base.status as planStatus,
base.description,
s.site_name,
base.create_user_id planUserId,
user.user_name planUserName
from inspection_store_plan_base base
inner join site_base s on base.site_id = s.id
inner join inspection_store_plan_type_rela tr on base.id = tr.plan_id
inner join inspection_store_type t on tr.type_id = t.id
inner join user on base.create_user_id = user.id
where base.member_id = #{paramsDto.memberId} and base.is_del = 0 and
((date_format(base.plan_date,'%Y%m%d') - (date_format(now(), '%Y%m%d')))>=0)
group by tr.plan_id
order by base.status desc,base.plan_date asc,base.id desc)t1
下班记得打卡