- [ 数据库由sqlserver更换为mysql,withas不能使用,求指点,转换为mysql可以用的sql语句]
WITH allSorts AS (
SELECT s.*
FROM Sort s
where s.isDel = 0
and s.kid = #{sortKid}
UNION ALL
SELECT s.*
FROM Sort s
INNER JOIN allSorts a ON a.parentId = convert(varchar (36), s.kid)
WHERE s.isdel = 0
)
select c.*
from ContractInfo c
inner join SectionInfo s on c.sectionIds = convert(varchar (36), s.kid)
inner join (select top 1 * from allSorts where allSorts.isdel = 0 ORDER BY iid asc) a
on a.parentId = convert(varchar (36), s.kid)
where c.isdel = 0
and s.isdel = 0
and c.contractType = 4