用到两个case语句,效率可能低一些。后续有需要再优化吧。
select
case when t.st_range_start>t.st_range_end then t.st_range_start ELSE t.st_range_end end as big,
case when t.st_range_start<=t.st_range_end then t.st_range_start ELSE t.st_range_end end as little
FROM
(SELECT hd_st.hd_id,st_sd.sd_id,st_range_start,st_range_end FROM hd_st JOIN st_sd ON hd_st.st_id=st_sd.st_id WHERE hd_st.hd_id='1088790') as t