新增違規次數多的API

This commit is contained in:
威勝 張 2024-02-06 00:34:29 +08:00
parent e210b04ef3
commit c85f06c8f2

View File

@ -179,6 +179,31 @@ namespace WebApi_data_value.Controllers
} }
#endregion #endregion
#region
/// <summary>
/// 尋找違規次數最多
/// </summary>
/// <returns></returns>
[HttpGet("recidivists")]
public async Task<IEnumerable<object>> GetRecidivists()
{
var plateNumberOccurrences = await _context.violation_car_table
.GroupBy(c => c.license_plate_number)
.Select(group => new
{
LicensePlateNumber = group.Key,
Occurrences = group.Count()
})
.OrderByDescending(x => x.Occurrences)
.ToListAsync();
return plateNumberOccurrences;
}
#endregion
#region #region
/// <summary> /// <summary>
/// 新增違規車輛 /// 新增違規車輛