0

I am working on an application in asp.net window application whose data stored in excel sheet. I have a sheet in excel: Sheet2(STATE,Point) on the basis of points the each state gets medals which has following criteria:- Gold : 7 points Silver : 5 Points Bronze : 4 Points

I want total medal of each STATE on the basis of their medals type means the STATE having most gold medal should be top.If 2 STATE have same number of Gold then the STATE having more silver medals should be on higher position.And if 2 STATE have same number of silver medals then the STATE having more Bronze medals should be on higher position. I have done following query:-

OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["SportTech"].ConnectionString);
//string query = "select STATE,sum(Point) as MEDAL from [Sheet2$] Group by STATE order by sum(Point) desc";
//string query = "SELECT STATE,SUM(Point) AS MEDAL,(CASE Point == 7: 1 END) AS GoldCount FROM [Sheet2$] GROUP BY STATE ORDER BY SUM(Point) DESC";
string query = "select STATE,sum(Point) as MEDAL, sum(IIF(point = 7,1,0)) as Gold, sum(IIF(point = 5,1,0)) as Silver, sum(IIF(point = 4,1,0)) as Bronce from [Sheet2$] group by STATE order by sum(IIF(point = 7,1,0)) desc";
OdbcCommand cmd = new OdbcCommand(query, con);
OdbcDataAdapter da = new OdbcDataAdapter(cmd);
con.Open();
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();

but the query is not working if 2 STATE having similar Gold or Silver medals.kindly help me..Thanx

4

1 回答 1

1

假设您对奖牌的计算有效,您应该能够简单地将额外的参数添加到 ORDER BY 子句,如下所示:

string query = "select STATE,sum(Point) as MEDAL, sum(IIF(point = 7,1,0)) as Gold, sum(IIF(point = 5,1,0)) as Silver, sum(IIF(point = 4,1,0)) as Bronce from [Sheet2$] group by STATE order by sum(IIF(point = 7,1,0)) desc,  sum(IIF(point = 5,1,0)) desc,  sum(IIF(point = 4,1,0)) desc";
于 2013-09-21T14:09:27.810 回答