我有这个代码,我首先需要找到ENROLL_PERIOD
最低的学生,然后找到join
grades
表的学生。问题是我的表students
中的数据存储为文本。因此,在我正确排序数据之前,我需要使用cast
函数,并使表ENROLL_PERIOD
中的students
成为整数。但是我应该把它放在代码中?我一直在收到语法错误。希望有人可以帮助我!
答案 0 :(得分:0)
我相信你想要:
Select *
from (select top (100) s.*
from students s
where PERSON_ID <> ''
order by TRY_CAST(KonvENROLL_PERIOD AS INT)
) s
join grades g
on s.PERSON_ID = g.PERSON_ID
答案 1 :(得分:0)
该列属于select
。另外,使用try_cast()
来避免错误:
Select *
from (select top (100) s.*, try_cast(ENROLL_PERIOD AS int) AS KonvENROLL_PERIOD
from students s
where PERSON_ID <> ''
order by KonvENROLL_PERIOD ASC
) s inner join
grades g
on s.PERSON_ID = g.PERSON_ID;