我正在尝试从表格中选择3列的最大值。从查询返回的所有字段都是字符串。
我有什么安慰
var step1 = from result in t_hsbc_staging_trts_derived_tbl_ac_balance.AsQueryable()
where result.branch_no == brnchnu
&& result.deal_id == dealid
&& result.group_mbr == grpmem
&& result.ac_type != "RMC"
select result ;
var branch = from result in step1
select new {ccbranch = result.cc_branch.Max()};
var sect = from result in step1
select new { ccsect = result.cc_sect.Max()};
var dept = from result in step1
select new { ccdept = result.cc_dept.Max()};
foreach (var result in branch)
{
string cc_branch = result.ccbranch.ToString();
}
我在foreach声明中得到的错误是:
类型'System.String'不支持序列运算符。
必须有一种更简单的方法来从此表中获取最大值?
答案 0 :(得分:2)
您正在Max()
上调用result.cc_branch
函数,该函数本身就是一个字符串。即使它成功了,它也会返回具有最大unicode号的字符串的字符,即
string s = "one-two-three";
Console.WriteLine(s.Max()); // returns 'w'
由于我认为这不是您想要的,并且您想要最大的分支/部门/部门值,您可以使用:
string branch = (from result in step1 select result.cc_branch).Max();
string sect = (from result in step1 select result.cc_sect).Max();
string dept = (from result in step1 select result.cc_dept).Max();