MS SQL OrderBy组的设置标准
本文关键字:设置 标准 SQL OrderBy MS | 更新日期: 2023-09-27 18:06:55
我需要把这个Linq order语句翻译成SQL:
list = list.OrderByDescending(x => x.Gender == "f" && x.IsCouple == 0)
.ThenByDescending(x => x.ApprovalRejectedDate)
.ThenByDescending(x => x.Id);
简单地拥有:
ORDER BY x.Gender, x.IsCouple, x.ApprovalRejectedDate, x.Id
返回不同的顺序,因为第一组条件需要匹配在一起。
任何想法我怎么能做到这一点在SQL?
order by
case when x.Gender = 'f' and x.IsCouple = 0 then 1 else 0 end,
x.ApplrovalRejectedDate desc,
x.Id desc