Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You already have a Boolean condition: "MIN("Grade - Current"."Grade Equivalency")=MIN("Grade - Current"."Grade Equivalency")" in your when, so you cannot also do an IN clause too.</p> <p>Also when you use the IN clause in the parenthesis you have to put values not table columns.</p> <p>Maybe you need something like:</p> <pre><code>case when MIN("Grade - Current"."Grade Equivalency")=MIN("Grade - Current"."Grade Equivalency") AND MIN("Grade - Current"."Grade Equivalency") IN (one or more values...) then 'y' else 'n' end </code></pre> <p><strong>Second answer...</strong></p> <p>It's a little more complex, as it uses analytical functions.</p> <p>Take a look below:</p> <pre><code>select RECORDKEY, VERSION_YEAR, GRADE, case when GRADE_PREV = 0 and GRADE_NEXT &gt;= 0 then 'Stayed the same' when GRADE_PREV = 0 and GRADE_NEXT &gt; 0 then 'Stayed the same' when GRADE_PREV &gt; 0 and GRADE_PREV &lt; GRADE then 'increased' when GRADE_PREV &gt; 0 and GRADE_PREV &gt; GRADE then 'decreased' else null end as grade_change from ( select RECORDKEY, VERSION_YEAR, GRADE ,LAG(GRADE, 1, 0) over (partition by RECORDKEY order by RECORDKEY, VERSION_YEAR) as GRADE_PREV ,LEAD(GRADE, 1, 0) over (partition by RECORDKEY order by RECORDKEY, VERSION_YEAR) as GRADE_NEXT from PLCH_GRADES ) order by 1,2 </code></pre> <p><strong>Third answer...</strong></p> <p>Here it is, now integrating your "original" query:</p> <pre><code>select RECORDKEY, CALENDAR_YEAR, HEADCOUNT, GRADE, case when GRADE_PREV = 0 and GRADE_NEXT &gt;= 0 then 'Stayed the same' when GRADE_PREV = 0 and GRADE_NEXT &gt; 0 then 'Stayed the same' when GRADE_PREV &gt; 0 and GRADE_PREV &lt; GRADE then 'increased' when GRADE_PREV &gt; 0 and GRADE_PREV &gt; GRADE then 'decreased' else NULL end as GRADE_CHANGE from ( select RECORDKEY, CALENDAR_YEAR, HEADCOUNT, GRADE ,LAG(GRADE, 1, 0) over (partition by RECORDKEY order by RECORDKEY, VERSION_YEAR) as GRADE_PREV ,LEAD(GRADE, 1, 0) over (partition by RECORDKEY order by RECORDKEY, VERSION_YEAR) as GRADE_NEXT from ( select PEOPLE."Record Key" as RECORDKEY, CALENDAR.year as CALENDAR_YEAR, "Grade - Current"."Grade Equivalency" as GRADE, "Fact - People".HEADCOUNT from test where location = 'NI' and PEOPLE."Status Group" = 'CURRENT' and PEOPLE."Headcount Marker" in ('Paid', 'Unpaid') AND Calendar.Year IN ('2009', '2012') ) ) order by 1,2 </code></pre>
    singulars
    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