首页 > 解决方案 > 两列中的 OrderBy 记录 ASC

问题描述

我正在尝试在 Windows 应用程序中以大声的形式对我的列进行 OrderBy。我尝试使用此代码:

using (SqlCommand sqlcomm = new SqlCommand("SELECT * FROM remaining WHERE username=@username and status=@status and company_status=@company_status ORDER BY call_case ASC , Payment_Status ASC", sqlconn))

这是正确的方法吗?

我正在寻找的是 OrderBy (call_case) ASC,当 call_case= (2-Answer) OrderBy (Payment_Status) ASC 时。

 (  call_case ), ( Payment_Status )

   null    ,    null 

   1-No Answer ,    null

   2-answer    ,    1-Promise Payment

   2-answer    ,    2-Have Problem

   2-answer    ,    3-Reject Payment

   3- not Exist ,      null

我有一个注释,我可以帮助文本以数字开头,例如 1-No Answer 、2-answer 、3- not Exist

标签: c#form-load

解决方案


您可以将CASE表达式与ORDER BYlike一起使用

SELECT * FROM remaining 
WHERE username=@username 
and status=@status 
and company_status=@company_status 
ORDER BY      
   case when call_case='Answer' then 0 else 1 end ASC,      
   Payment_Status ASC

推荐阅读