实际上,我得到了list of top 5 countires based on count
这样的:
select top 5 COUNT(distinct FROM_EMAILID) as Count,
FROM_COUNTRY from SURVEY_VISITORS
where TEMPLATE_ID=79 and FROM_COUNTRY<>'undefined'
group by FROM_COUNTRY order by COUNT desc
现在,我需要转换成 Linq,但无法做到。
我曾尝试使用这样的子查询来获得前 1 个国家/地区。但是对于前 5 个国家/地区,我有点困惑:
var innerQuery = (from t in VDC.SURVEY_VISITORS
group t by new
{
t.FROM_COUNTRY
} into g
orderby
g.Count() descending
select new
{
VisitorCount = (Int64?)g.Count(),
Country = g.Key.FROM_COUNTRY
}).FirstOrDefault();
var result = (from xx in VDC.SURVEY_VISITORS
where ((innerQuery.Country.Contains(xx.FROM_COUNTRY))
&& xx.TEMPLATE_ID == 79)
select new
{
xx.FROM_COUNTRY,
xx.FROM_EMAILID
}).Distinct().ToList();
我的结果应该是:
任何帮助将不胜感激。