0

以下是正在使用的查询。weightagepercentage这里根据列中的数据获取列的总和status

Status|WeightPer
___________________
P     | 2
F     | 3
F     | 1
P     | 1


SELECT Status, 
       SUM(WeightagePercent) AS Final
FROM ProoferTbl
GROUP BY Status

决赛有

F=4
P=3

我需要将结果保存在 2 个变量中通过和失败的值并将它们比较为最大。有可能这样做还是我必须改变一些东西?

4

1 回答 1

0
SqlConnection con = new SqlConnection("...");
string strSQL = "SELECT SUM(case when Status = 'P' then WeightagePercent else 0 end) as passed, " + 
                "       SUM(case when Status = 'F' then WeightagePercent else 0 end) as failed " + 
                "FROM ProoferTbl2 " + 
                "GROUP BY Status";
SqlCommand cmd = new SqlCommand(strSQL, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();   
int passed = 0, failed = 0; 
while (reader.Read())
{
    passed = (int) reader["passed"];
    failed = (int) reader["failed"];
}
reader.Close();
con.Close();
If(passed > failed)
{ 
    Messagebox.show("Pass")
}
于 2013-11-08T10:52:18.827 回答