SELECT (count(Competency_Id) * 100 /(Select count(Competency_Id) from [dbo].[QLs]))
as Percentage ,[dbo].[Competencies].Name as CompetencyName
FROM [dbo].[QLs]
INNER JOIN [dbo].[Competencies]
ON [dbo].[QLs].Competency_Id= [dbo].[Competencies].Id
GROUP BY dbo.[QLs].Competency_Id,dbo.[Competencies].Name
我需要帮助从上面提到的SQL查询创建一个Linq。请协助。感谢
答案 0 :(得分:0)
var query = (from u in db.QLs
join c in db.Competencies on u.Competency_Id equals c.Id
let total = db.QLs.Count()
group u by new
{
Competency_Id = u.Competency_Id,
Name = c.Name,
total = total
} into g
select new QLbyCompetencyPieChart
{
Percentage = (float)(100 * g.Count()) / ((float)g.Key.total),
Competency= g.Key.Name,
Color=null
}).AsQueryable();