Quantcast
Channel: Go4Expert
Viewing all articles
Browse latest Browse all 1987

Speed up Aggregation Functions by Multiple Subqueries

$
0
0
A SQL statement with multiple aggregation functions like the following and the emps_salary and emps_id are indexed. If you find the SQL is slow and want to speed up the SQL

SELECT min(emps_salary), max(emps_id), count(*)
FROM employees

You can rewrite the SQL into the following syntax, the new syntax may better utilize Fast/Full Index Scan.

Try it and have fun….

WITH
t1 (Min_salary) as (select min(emps_salary) from employees),
t2 (Max_emps_id) as (select max(emps_id) from...

Speed up Aggregation Functions by Multiple Subqueries

Viewing all articles
Browse latest Browse all 1987

Trending Articles