The following statement work fine:
SELECT DISTINCT
woas.assessmentid,
woas.workorderid FROM wo_assessment
LEFT JOIN wo_assessment woas ON woas.assessmentid = woas.assessmentid
LEFT JOIN wo_group_info wogi ON woas.assessmentid=wogi.assessmentid
However when I add the below sub query, I get a generic error about the FROM clause 'ERROR: syntax error at or near "FROM"'
first_value(wogi.groupid ) over (partition by value_partition ORDER BY woas.assessmentid)
FROM (SELECT woas.assessmentid,wogi.groupid, sum(case when wogi.groupid is null then 0 else 1 end) over (ORDER BY woas.assessmentid) as value_partition
FROM wo_assessment
ORDER BY woas.assessmentid) as q
Here is the complete code:
SELECT DISTINCT
woas.assessmentid,
woas.workorderid,
first_value(wogi.groupid ) over (partition by value_partition ORDER BY woas.assessmentid)
FROM (SELECT woas.assessmentid,wogi.groupid, sum(case when wogi.groupid is null then 0 else 1 end) over (ORDER BY woas.assessmentid) as value_partition
FROM wo_assessment
ORDER BY woas.assessmentid) as q FROM wo_assessment
LEFT JOIN wo_assessment woas ON woas.assessmentid = woas.assessmentid
LEFT JOIN wo_group_info wogi ON woas.assessmentid=wogi.assessmentid
I cant for the life of me understand why it wont validate, any help greatly appreciated.
Latest attempt, it now says by sub query returns more that one result.
SELECT DISTINCT
woas.assessmentid,
woas.workorderid,
first_value(wogi.groupid ) over (partition by value_partition ORDER BY woas.assessmentid) ,
(SELECT woas.assessmentid,wogi.groupid, sum(case when wogi.groupid is null then 0 else 1 end) over (ORDER BY wo.assessmentid) as value_partition
FROM wo_assessment wo LEFT JOIN wo_assessment woas ON woas.assessmentid = wo.assessmentid WHERE woas.assessmentid = wo.assessmentid ORDER BY wo.assessmentid) as q FROM wo_assessment
LEFT JOIN wo_assessment woas ON woas.assessmentid = woas.assessmentid
LEFT JOIN wo_group_info wogi ON woas.assessmentid=wogi.assessmentid