Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might try this version (I'm assuming the <code>E</code> references are supposed to be the <code>ES</code> alias, otherwise the statement shouldn't run). Among other things, you should ditch the 'implicit join' (comma-separated <code>FROM</code> clause), especially if you ever start dealing with <code>LEFT JOIN</code>s.</p> <pre><code>WITH Maximum_Salary (max) as (SELECT MAX(EMP.SALARY) FROM EMPLOYEE EMP JOIN FINANCIAL_YEAR FY ON (FY.CURRENT_DT - 2 DAYS) &gt;= EMP.DATE_TS AND (FY.CURRENT_DT - 1 DAYS) &lt; EMP.DATE_TS WHERE EMP.JOIN_DT = DATE('2013-01-01') SELECT EMP.STATUS, COUNT(*) AS EMP_COUNT, GRP.GROUP_NAME FROM EMPLOYEE EMP JOIN GROUP_TABLE GRP ON GRP.RANGE_SALARY = 'BAND-10' JOIN EMPLOYEE_SALARY ES ON ES.EMPID = EMP.SALARY AND ES.SALARY_GRP = GRP.BAND_GROUP JOIN Maximum_Salary ON Maximum_Salary &lt;= EMP.SALARY GROUP BY EMP.STATUS, GRP.GROUP_NAME </code></pre> <p>If you aren't used to them already, the <code>WITH</code> syntax is a Common Table Expression (or CTE) - effectively, it's an inline view. These <em>can</em> result in temp-tables being created, in some instances, but otherwise can save you a lot of typing (they're also how recursive queries are performed). I've managed to get the references to <code>EMP.DATE_TS</code> into a form that can use an index (no help for the date-math on <code>FY.CURRENT_DT</code>, although as a small table that shouldn't matter much).</p> <p>Note that you may still need to perform additional tuning, especially depending on what indices you may (not) have.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload