-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsomeQueries.cs
More file actions
31 lines (30 loc) · 961 Bytes
/
Copy pathsomeQueries.cs
File metadata and controls
31 lines (30 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// PSQL
// SELECT
// "t"."Id" AS "TeamId",
// "t"."Name" AS "TeamName",
// COALESCE(SUM("dr"."Points"), 0) AS "TotalPoints",
// RANK() OVER (ORDER BY COALESCE(SUM("dr"."Points"), 0) DESC) AS "Ranking"
// FROM public."Teams" AS "t"
// LEFT JOIN public."Drivers" AS "d" ON "t"."Id" = "d"."TeamId"
// LEFT JOIN public."DriverRaces" AS "dr" ON "d"."Id" = "dr"."DriverId"
// GROUP BY "t"."Id", "t"."Name"
// ORDER BY "TotalPoints" DESC;
//Entity queries
// var teamRankings = await _context.Teams
// .Select(t => new
// {
// TeamId = t.Id,
// TeamName = t.Name,
// TotalPoints = t.Drivers
// .SelectMany(d => d.DriverRaces)
// .Sum(dr => (int?)dr.Points) ?? 0
// })
// .OrderByDescending(t => t.TotalPoints)
// .Select((t, index) => new
// {
// t.TeamId,
// t.TeamName,
// t.TotalPoints,
// Ranking = index + 1
// })
// .ToListAsync();