我想更新一个表。但是查询返回错误
派生表“colIndex”不可更新,因为它包含聚合或 DISTINCT 或 GROUP BY 子句
我怎样才能做到这一点?如果没有直接的方式,也建议任何替代方式。
包括查询:
UPDATE COLINDEX
SET
COLINDEX.QRESID = ROWINDEX.FRESID
FROM (SELECT QE.COLID,PS.ID SECID,PS.T_ID TEMPLATEID,QE.QUESTIONID,
MIN(QE.SEQNUM) SEQNUM, Q.QRESID
FROM SECTION PS
JOIN SECTIONQUESTIONLINK SX ON PS.ID = SX.SECID
JOIN QUESTION Q ON SX.QUESTIONID=Q.ID
JOIN ELEMENT QE ON SX.QUESTIONID=QE.QUESTIONID
WHERE QE.CONTROLID<>12
GROUP BY PS.ID,COLID,PS.T_ID,QE.QUESTIONID ,Q.QRESID)COLINDEX
JOIN (SELECT QE.SEQNUM FSEQNO,QE.ERESID FRESID,PS.ID SECID,PS.T_ID TEMPLATEID,QE.COLID FROM SECTION PS
JOIN SECTIONQUESTIONLINK SX ON PS.ID = SX.SECID
JOIN ELEMENT QE ON SX.QUESTIONID=QE.QUESTIONID
WHERE QE.CONTROLID=12 AND QE.SEQNUM <= PS.COLUMNS + PS.ROWLABEL)ROWINDEX
ON COLINDEX.SECID=ROWINDEX.SECID AND COLINDEX.COLID=ROWINDEX.COLID
AND COLINDEX.TEMPLATEID=5000
从这个查询的一部分正确地提取我想要更新的行。