正確答案: select count(*) as TotalEvents, eventname, errorcode, errormessage from cloudtrail_logs where errorcode is not null and eventtime >= '2024-01-01T00:00:00Z' group by eventname, errorcode, errormessage order by TotalEvents desc limit 10;.
為什麼這是答案
正確答案符合所有要求:errorcode is not null 過濾出帶有錯誤的事件;eventtime = '2024-01-01T00:00:00Z' 篩選出指定日期之後的事件;group by eventname, errorcode, errormessage 將相同的錯誤事件分組;order by TotalEvents desc 依據事件發生次數降序排列;最後 limit 10 顯示前 10 個最常發生的錯誤。
其他選項的錯誤在於:
第二個選項缺少 errorcode is not null 條件,會包含沒有錯誤碼的事件。
第三個選項的 order by eventname asc 排序方式不符合「發生次數最多的前 10 個」要求。
第四個選項缺少 order by TotalEvents desc,導致 limit 10 無法正確選出發生次數最多的前 10 個錯誤。