hsql に CREATE VIEW クエリがありますが、実行するたびに次のエラーがスローされます。
集計列または GROUP BY 列にない式: AGV.ID
集計式 (AVG、SUM、MIN、MAX) がないと GROUP BY が機能しないことは理解していますが、クエリを修正する方法がわかりません。各レコードを manifestID 値でグループ化する必要があるためです。
基本的に、3セットの選択クエリを組み合わせてVIEWを作成しようとしています。
複数の選択した列があると機能しないため、個別を使用しようとしましたが、うまくいきませんでした。このクエリは MYSQL で正常に機能します。
私のクエリ:
CREATE VIEW local_view_event_manifest(
manifest_id,
eventId,
eventType,
eventDate,
manifestID,
businessStepStr,
manifestVersion,
externalLocation,
remark,
epcCode,
locationCode
)
AS
SELECT
agm.manifest_id AS manifest_id,
agv.id AS eventId,
'AGGREGATION_EVENT' AS eventType,
agv.event_time AS eventDate,
md.manifest_id AS manifestID,
agv.business_step_code AS businessStepStr,
md.manifest_version AS manifestVersion,
md.external_location AS externalLocation,
md.remark AS remark,
epc.code as epcCode,
bloc.location_code as locationCode
FROM
"local".local_MANIFEST_DATA AS md,
"local".local_AGGREGATION_EVENT AS agv,
"local".local_AGGREGATION_EVENT_EPCS AS agv_epc,
"local".local_EPC AS epc,
"local".local_BUSINESS_LOCATION AS bloc,
"local".local_AGGREGATION_EVENT_MANIFEST_DATA AS agm
WHERE
md.id=agm.manifest_id
AND agv.deleted=0
AND md.deleted=0
AND agv.id=agm.aggregation_event_id
AND agv.id=agv_epc.aggregation_event_id
AND agv.business_location_id=bloc.id
AND bloc.id=agv.business_location_id
AND agv_epc.epc_id=epc.id
GROUP BY agm.manifest_id
UNION
SELECT
om.manifest_id AS manifest_id,
ov.id AS eventId,
'OBJECT_EVENT' AS eventType,
ov.event_time AS eventDate,
md.manifest_id AS manifestID,
ov.business_step_code AS businessStepStr,
md.manifest_version AS manifestVersion,
md.external_location AS externalLocation,
md.remark AS remark,
epc.code as epcCode,
bloc.location_code as locationCode
FROM
"local".local_MANIFEST_DATA AS md,
"local".local_OBJECT_EVENT AS ov,
"local".local_OBJECT_EVENT_EPCS AS ov_epc,
"local".local_EPC AS epc,
"local".local_BUSINESS_LOCATION AS bloc,
"local".local_OBJECT_EVENT_MANIFEST_DATA AS om
WHERE
md.id=om.manifest_id
AND ov.deleted=0
AND md.deleted=0
AND ov.id=ov_epc.object_event_id
AND ov.id=om.object_event_id
AND bloc.id=ov.business_location_id
AND ov_epc.epc_id=epc.id
GROUP BY om.manifest_id
UNION
SELECT
trm.manifest_id AS manifest_id,
trv.id AS eventId,
'TRANSACTION_EVENT' AS eventType,
trv.event_time AS eventDate,
md.manifest_id AS manifestID,
trv.business_step_code AS businessStepStr,
md.manifest_version AS manifestVersion,
md.external_location AS externalLocation,
md.remark AS remark,
epc.code as epcCode,
bloc.location_code as locationCode
FROM
"local".local_MANIFEST_DATA AS md,
"local".local_TRANSACTION_EVENT AS trv,
"local".local_TRANSACTION_EVENT_EPCS AS trv_epc,
"local".local_EPC AS epc,
"local".local_BUSINESS_LOCATION AS bloc,
"local".local_TRANSACTION_EVENT_MANIFEST_DATA AS trm
WHERE
md.id=trm.manifest_id
AND trv.deleted=0
AND md.deleted=0
AND trv.id=trv_epc.transaction_event_id
AND trv.id=trm.transaction_event_id
AND bloc.id=trv.business_location_id
AND trv_epc.epc_id=epc.id
GROUP BY trm.manifest_id
以下は、GROUP BY を使用した場合と GROUP BY を使用しない場合の mysql でのクエリ結果のスナップショットです。
T
@fredt ...詳細な説明をありがとう..あなたの提案を参照して、私はそれを試しました..しかし、どういうわけかこのエラーが発生します:
エラー: テーブルが見つかりません: ステートメントの TABL_B [SELECT TABL_B.* FROM (SELECT DISTINCT manifest_id FROM "local".local_AGGREGATION_EVENT_MANIFEST_DATA) TABL_A] エラー コード: -22
以下は私のクエリです:
SELECT TABL_B.* FROM (SELECT DISTINCT manifest_id FROM "local".local_AGGREGATION_EVENT_MANIFEST_DATA) TABL_A
LATERAL JOIN
( SELECT
agm.manifest_id AS manifest_id,
agv.id AS eventId,
'AGGREGATION_EVENT' AS eventType,
agv.event_time AS eventDate,
md.manifest_id AS manifestID,
agv.business_step_code AS businessStepStr,
md.manifest_version AS manifestVersion,
md.external_location AS externalLocation,
md.remark AS remark,
epc.code as epcCode,
bloc.location_code as locationCode
FROM
"local".local_MANIFEST_DATA AS md,
"local".local_AGGREGATION_EVENT AS agv,
"local".local_AGGREGATION_EVENT_EPCS AS agv_epc,
"local".local_EPC AS epc,
"local".local_BUSINESS_LOCATION AS bloc,
"local".local_AGGREGATION_EVENT_MANIFEST_DATA AS agm
WHERE
md.id=agm.manifest_id
AND agv.deleted=0
AND md.deleted=0
AND agv.id=agm.aggregation_event_id
AND agv.id=agv_epc.aggregation_event_id
AND agv.business_location_id=bloc.id
AND bloc.id=agv.business_location_id
AND agv_epc.epc_id=epc.id AND manifest_id = TABL_A.manifest_id LIMIT 1 ) TABL_B
ありがとう@fredt ..コンマに気づき、すでにクエリに追加されています。JOIN単語も削除してみました。しかし、それでも同じエラーがスローされます..
ERROR: Table not found in statement [SELECT TABL_B.* FROM (SELECT
DISTINCT MANIFEST_ID FROM "local".local_AGGREGATION_EVENT_MANIFEST_DATA)
AS TABL_A, LATERAL] Error Code: -22