xx yy zz
1 2 3
2 3 2
3 4 6
遍历每一行,求出yy*zz的值,比较求出yy*zz的最大值
6 个解决方案
#1
select yy*zz as t from tb
while(reader.Read());
{
//获取最大值
}
或DataTable.Compute("max(yy*zz)","")
while(reader.Read());
{
//获取最大值
}
或DataTable.Compute("max(yy*zz)","")
#2
var abc = from c in dt.AsEnumerable()
select new
{
AB = c.Field<int>("yy") * c.Field<int>("zz")
};
int b = abc.Max(p => p.AB);
select new
{
AB = c.Field<int>("yy") * c.Field<int>("zz")
};
int b = abc.Max(p => p.AB);
#3
int max=0;
DataTable dt = new DataTable();
foreach (DataRow dr in dt.Rows)
{
int num = Convert.ToInt32(dr["yy"]) *Convert.ToInt32(dr["zz"]);
if (num>max)
{
max = num;
}
}
//the max number is num
Response.Write(string.Format("<script>alert('最大值为{0}')</script>",max.ToString()));
DataTable dt = new DataTable();
foreach (DataRow dr in dt.Rows)
{
int num = Convert.ToInt32(dr["yy"]) *Convert.ToInt32(dr["zz"]);
if (num>max)
{
max = num;
}
}
//the max number is num
Response.Write(string.Format("<script>alert('最大值为{0}')</script>",max.ToString()));
#4
float maxValue = -99999.0; //取一很小的数
flaot[] mathValue = new float[Table["表名"].Rows.Count]
foreach(DataRow myRows in Table["表名"].Rows)
{
mathValue = myRows["yy"] * myRows["zz"];
maxValue = maxValue > mathValue ? maxValue : mathValue;
}
flaot[] mathValue = new float[Table["表名"].Rows.Count]
foreach(DataRow myRows in Table["表名"].Rows)
{
mathValue = myRows["yy"] * myRows["zz"];
maxValue = maxValue > mathValue ? maxValue : mathValue;
}
#5
各位大侠,我是能算出最大值了,题目我忘记说了,是要取出最大值,还有那一行相应的一个字段(如疾病),然后存在一个什么列表还是什么的里面,就是 取出来的形式是: 感冒 概率最大0.4
#6
var abc = from c in dt.AsEnumerable()
orderby c.Field<int>("yy") * c.Field<int>("zz") descending
select c;
var b = abc.First();
Console.WriteLine(b.Field<int>("yy")+"|"+b.Field<int>("zz"));
orderby c.Field<int>("yy") * c.Field<int>("zz") descending
select c;
var b = abc.First();
Console.WriteLine(b.Field<int>("yy")+"|"+b.Field<int>("zz"));
#1
select yy*zz as t from tb
while(reader.Read());
{
//获取最大值
}
或DataTable.Compute("max(yy*zz)","")
while(reader.Read());
{
//获取最大值
}
或DataTable.Compute("max(yy*zz)","")
#2
var abc = from c in dt.AsEnumerable()
select new
{
AB = c.Field<int>("yy") * c.Field<int>("zz")
};
int b = abc.Max(p => p.AB);
select new
{
AB = c.Field<int>("yy") * c.Field<int>("zz")
};
int b = abc.Max(p => p.AB);
#3
int max=0;
DataTable dt = new DataTable();
foreach (DataRow dr in dt.Rows)
{
int num = Convert.ToInt32(dr["yy"]) *Convert.ToInt32(dr["zz"]);
if (num>max)
{
max = num;
}
}
//the max number is num
Response.Write(string.Format("<script>alert('最大值为{0}')</script>",max.ToString()));
DataTable dt = new DataTable();
foreach (DataRow dr in dt.Rows)
{
int num = Convert.ToInt32(dr["yy"]) *Convert.ToInt32(dr["zz"]);
if (num>max)
{
max = num;
}
}
//the max number is num
Response.Write(string.Format("<script>alert('最大值为{0}')</script>",max.ToString()));
#4
float maxValue = -99999.0; //取一很小的数
flaot[] mathValue = new float[Table["表名"].Rows.Count]
foreach(DataRow myRows in Table["表名"].Rows)
{
mathValue = myRows["yy"] * myRows["zz"];
maxValue = maxValue > mathValue ? maxValue : mathValue;
}
flaot[] mathValue = new float[Table["表名"].Rows.Count]
foreach(DataRow myRows in Table["表名"].Rows)
{
mathValue = myRows["yy"] * myRows["zz"];
maxValue = maxValue > mathValue ? maxValue : mathValue;
}
#5
各位大侠,我是能算出最大值了,题目我忘记说了,是要取出最大值,还有那一行相应的一个字段(如疾病),然后存在一个什么列表还是什么的里面,就是 取出来的形式是: 感冒 概率最大0.4
#6
var abc = from c in dt.AsEnumerable()
orderby c.Field<int>("yy") * c.Field<int>("zz") descending
select c;
var b = abc.First();
Console.WriteLine(b.Field<int>("yy")+"|"+b.Field<int>("zz"));
orderby c.Field<int>("yy") * c.Field<int>("zz") descending
select c;
var b = abc.First();
Console.WriteLine(b.Field<int>("yy")+"|"+b.Field<int>("zz"));