以下声明可以正常使用:
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
但是当我添加下面的子查询时,我得到一个关于FROM子句的错误的通用错误'错误:语法错误在“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
以下是完整的代码:
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
我不能理解为什么它不会验证,任何帮助都非常感激。
最新尝试,现在通过子查询说明会返回多一个结果。
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