使用混合列数据类型按大小写排序
order by and case with mixed column datatype
我们需要将 order by 与 case 子句一起使用,因为用户可以从下拉列表中选择订单类型。在引入具有整数值的列 wa 之前,情况似乎还不错。似乎出于某种原因, MYSQL 也假设整数列是一个字符串并同样排序..
以下是按条款排序
order by (case when p_SortBy = 'Default' then CONVERT(st.IncrementNo, unsigned)
WHEN p_SortBy ='Program'
THEN st.StudyProgram
WHEN p_SortBy = 'Student'
then st.Name
when p_SortBy = 'Mobile'
then st.Mobile
END) asc
第一种情况(默认)是一个整数值,但它是这样排序的
105,106,107,108,109,11,110
感谢任何帮助..
您可以使用多个 CASE
:
order by
case when p_SortBy = 'Default' then CONVERT(st.IncrementNo, unsigned) END,
case when p_SortBy = 'Program' then st.StudyProgram END,
case when p_SortBy = 'Student' then st.Name END,
case when p_SortBy = 'Mobile' then st.Mobile END
我们需要将 order by 与 case 子句一起使用,因为用户可以从下拉列表中选择订单类型。在引入具有整数值的列 wa 之前,情况似乎还不错。似乎出于某种原因, MYSQL 也假设整数列是一个字符串并同样排序..
以下是按条款排序
order by (case when p_SortBy = 'Default' then CONVERT(st.IncrementNo, unsigned)
WHEN p_SortBy ='Program'
THEN st.StudyProgram
WHEN p_SortBy = 'Student'
then st.Name
when p_SortBy = 'Mobile'
then st.Mobile
END) asc
第一种情况(默认)是一个整数值,但它是这样排序的
105,106,107,108,109,11,110
感谢任何帮助..
您可以使用多个 CASE
:
order by
case when p_SortBy = 'Default' then CONVERT(st.IncrementNo, unsigned) END,
case when p_SortBy = 'Program' then st.StudyProgram END,
case when p_SortBy = 'Student' then st.Name END,
case when p_SortBy = 'Mobile' then st.Mobile END