To find query duration average. declare @searchSQL varchar(max) ='%SELECT%vwVesselsEditableForms%join%tblEmployeePOAAccess%' SELECT qsp.query_id, QSP.plan_id, min(QSRS.first_execution_time) min_first_execution_time, max(QSRS.last_execution_time) max_last_execution_time, sum(qsrs.count_executions*QSRS.avg_duration/1000000) total_seconds, qsq.query_hash, qsp.query_plan_hash, avg(QSRS.avg_duration)/1000000 avg_duration_sec, sum(qsrs.count_executions) total_executions, min(qsrs.min_duration)/1000000 min_duration_sec,max(qsrs.max_duration)/1000000 max_duration_sec, QST.query_sql_text, qsp.query_plan FROM sys.query_store_plan AS QSP JOIN sys.query_store_query AS QSQ ON QSP.query_id = QSQ.query_id JOIN sys.query_store_query_text AS QST ON QSQ.query_text_id = QST.query_text_id JOIN sys.query_store_runtime_stats QSRS ON QSP.plan_id =QSRS.plan_id where qst.query_sql_text like @searchSQL group...