我正在处理一个大查询以重新查看 SQL Express 数据库中的某些数据,我在合并两个查询时遇到了问题。
我已经尝试对全局第二个查询进行内部连接,但是由于我使用某个 GROUP BY 作为总和,所以我没有工作。
这是我当前的查询:
SELECT
col.CO_No as nom_commercial,
det.DO_PIECE AS ref_document,
det.AB_NO AS numero_abonnement,
det.CA_NUM AS compte_analytique,
det.CBMODIFICATION AS modified_on,
det.CT_NUMPAYEUR AS ref_societe_payeur,
det.DO_CONTACT AS contact,
det.DO_COORD01 AS nom_client_final1,
det.DO_COORD02 AS nom_client_final2,
det.DO_DATE AS date_emission,
det.DO_DEBUTPERIOD AS debut_periode,
det.DO_FINPERIOD AS fin_periode,
det.DO_REF AS numero_piece_externe,
det.DO_TIERS AS ref_societe_sage,
det.DO_TotalTTC - det.DO_TotalHTNet AS total_tva,
det.DO_TotalHTNet AS total_ht,
det.DO_TotalTTC AS total_ttc,
det.DO_TYPE AS type_document,
DOC.prix_revient_total,
det.DO_TotalHT - DOC.prix_revient_total as total_marge
FROM F_DOCENTETE as det, F_COLLABORATEUR as col
INNER JOIN
(SELECT
lg.DO_Piece,
SUM((lg.DL_Qte)*(lg.DL_PrixRU)) as prix_revient_total
FROM F_DOCLIGNE as lg
GROUP BY lg.DO_Piece
) AS DOC
ON det.DO_Piece = DOC.DO_Piece
WHERE det.CO_NO = col.CO_NO AND(det.DO_PIECE LIKE 'BC%')
由这两个单独的查询组成:(1)
SELECT
lg.DO_Piece,
SUM((lg.DL_Qte)*(lg.DL_PrixRU)) as prix_revient_total
from F_DOCLIGNE as lg
JOIN F_DOCENTETE
ON ((lg.DO_Piece = F_DOCENTETE.DO_Piece) AND(F_DOCENTETE.DO_PIECE LIKE 'BC%'))
JOIN F_COLLABORATEUR
ON F_DOCENTETE.Co_No = F_COLLABORATEUR.CO_NO
GROUP BY lg.DO_Piece, F_DOCENTETE.DO_Piece
(2)
SELECT
F_COLLABORATEUR.CO_NOM AS nom_commercial,
F_DOCENTETE.DO_PIECE AS ref_document,
F_DOCENTETE.AB_NO AS numero_abonnement,
F_DOCENTETE.CA_NUM AS compte_analytique,
F_DOCENTETE.CBMODIFICATION AS modified_on,
F_DOCENTETE.CT_NUMPAYEUR AS ref_societe_payeur,
F_DOCENTETE.DO_CONTACT AS contact,
F_DOCENTETE.DO_COORD01 AS nom_client_final1,
F_DOCENTETE.DO_COORD02 AS nom_client_final2,
F_DOCENTETE.DO_DATE AS date_emission,
F_DOCENTETE.DO_DEBUTPERIOD AS debut_periode,
F_DOCENTETE.DO_FINPERIOD AS fin_periode,
F_DOCENTETE.DO_REF AS numero_piece_externe,
F_DOCENTETE.DO_TIERS AS ref_societe_sage,
F_DOCENTETE.DO_TotalTTC - F_DOCENTETE.DO_TotalHTNet AS total_tva,
F_DOCENTETE.DO_TotalHTNet AS total_ht,
F_DOCENTETE.DO_TotalTTC AS total_ttc,
F_DOCENTETE.DO_TYPE AS type_document
FROM F_DOCENTETE, F_COLLABORATEUR
WHERE F_DOCENTETE.CO_NO = F_COLLABORATEUR.CO_NO AND(F_DOCENTETE.DO_PIECE LIKE 'BC%')
对我来说,它应该只合并'DO_Piece'值上的两个表(在两个表中都可用),但它不起作用,我有这个错误:
Msg 4104, Level 16, State 1, Line 30
L'identificateur en plusieurs parties "F_DOCENTETE.DO_Piece" ne peut pas être lié.
(我的 Visual Studio 是法语的)
Translated in English :
Msg 4104, Level 16, State 1, Line 30.
The multi-part identifier "F_DOCENTETE.DO_Piece" could not be bound.
我想了解原因以及如何纠正它。
感谢您的回答。