解决方案 »
- asp.net调用web service有那种方法
- 客户端用户如何将动态生成的aspx页面另存为到本地
- Internet Explorer 9 预览版 发布啦,高手们可以研究下啦
- 这个问题很棘手!!如何判断frame加载完毕!
- 关于Profile的匿名迁移问题
- Asp.Net当执行到Server.CreateObject("ChinaAsp.Upload")报错
- 谈出窗口刷新主页面问题?window.opener.refresh()报错
- 求对于单位员工的查询代码
- 怎么样将模板列指定为第几列?
- 谁来帮帮我?发送Mail的问题
- Calendar控件中加入子控件textbox,如何给子控件赋值和取出子控件的值
- asp.net页面 PageLoad事件之前获得到当前屏幕高宽
list.Add(new Country() { country = "USA", productname = "ipad", sum = 100000 });
list.Add(new Country() { country = "USA", productname = "mac air", sum = 200000 });
list.Add(new Country() { country = "CHINA", productname = "dell", sum = 100000 });
(from l in list group l by l.country into g select new { country = g.Key, productname = g.Max(x => x.productname), sum = g.Max(x => x.sum) }).ToList().ForEach(x => Console.WriteLine(x.country + "==" + x.productname + "==" + x.sum));
var finResult=from a in groupResultQuery
group a by a.country into cqqq
let max=cqqq.OrderByDescending(x=>x.sum).First()
select new
{
country = cqqq.Key,
pname=max.productname,
total=max.sum
};
foreach (var f in finResult)
{
Write(f.country + "," + f.pname + "," + f.total);
}
我的是net 3.5
let max=cqqq.OrderByDescending(x=>x.sum).First() 后面.First()方法没有。。
group a by a.Country into cqqq
from max in cqqq.OrderByDescending(x => x.Sum).Take(1)
select new
{
country = cqqq.Key,
pname = max.Productname,
total = max.Sum
}
select * from
(select row_number() over(partition by country order by [sum] desc) as rowid,* from list) as tmpwhere rowid<2
但生成的是SELECT [t1].[country], [t3].[productname] AS [pname], [t3].[sum] AS [total]
FROM (
SELECT [t0].[country]
FROM [List] AS [t0]
GROUP BY [t0].[country]
) AS [t1]
CROSS APPLY (
SELECT TOP (1) [t2].[productname], [t2].[sum]
FROM [List] AS [t2]
WHERE (([t1].[country] IS NULL) AND ([t2].[country] IS NULL)) OR (([t1].[country] IS NOT NULL) AND ([t2].[country] IS NOT NULL) AND ([t1].[country] = [t2].[country]))
ORDER BY [t2].[sum] DESC
) AS [t3]
ORDER BY [t3].[sum] DESC如何生成上面的SQL