我在Pervasive V11數據庫上進行了以下SQL調用。 我正在尋找工作,以便每個項目ID只獲得一行。Pervasive PSQL GROUP BY子句
SELECT
inventory_history.item_id AS 'ItemId',
RTrim(inventory_items.item_name) AS 'Description',
If(RTrim(trx_type) = 'P',SUM(change_quantity),'') AS 'QtyChangeP',
If(RTrim(trx_type) = 'P',SUM(history_cost_01+history_cost_02+history_cost_03+history_cost_04+history_cost_05+history_cost_06+history_cost_07+history_cost_08+history_cost_09+history_cost_10+history_cost_11+history_cost_12),'') AS 'CostChangeP',
If(RTrim(trx_type) = 'S',SUM(change_quantity),'') AS 'QtyChangeS',
If(RTrim(trx_type) = 'S',SUM(history_cost_01+history_cost_02+history_cost_03+history_cost_04+history_cost_05+history_cost_06+history_cost_07+history_cost_08+history_cost_09+history_cost_10+history_cost_11+history_cost_12),'') AS 'CostChangeS',
If(RTrim(trx_type) = 'A',SUM(change_quantity),'') AS 'QtyChangeA',
If(RTrim(trx_type) = 'A',SUM(history_cost_01+history_cost_02+history_cost_03+history_cost_04+history_cost_05+history_cost_06+history_cost_07+history_cost_08+history_cost_09+history_cost_10+history_cost_11+history_cost_12),'') AS 'CostChangeA',
If(RTrim(trx_type) = 'T',SUM(change_quantity),'') AS 'QtyChangeT',
If(RTrim(trx_type) = 'T',SUM(history_cost_01+history_cost_02+history_cost_03+history_cost_04+history_cost_05+history_cost_06+history_cost_07+history_cost_08+history_cost_09+history_cost_10+history_cost_11+history_cost_12),'') AS 'CostChangeT',
If(RTrim(inventory_categories.stocked_by_factor) = 'FT',inventory_items.unit_weight,'') AS 'WtPerFt'
FROM
inventory_history
INNER JOIN
inventory_items ON inventory_history.item_id = inventory_items.item_id
INNER JOIN
inventory_categories ON inventory_items.category_id = inventory_categories.category_id
WHERE
trx_date>'20170731'
GROUP BY
inventory_history.item_id, inventory_items.item_name, trx_type, stocked_by_factor, unit_weight;
因爲它是現在,我收到來自數據庫的錯誤,如果我沒有trx_type,stocked_by_factor,或unit_weight在集團上市By子句。
刪除這些字段會導致此錯誤:
Column invalid. Must be a group by column: trx_type in SELECT LIST.
下面是完整的SQL調用的抽查結果:
ItemId Description QtyChangeP CostChangeP QtyChangeS CostChangeS QtyChangeA CostChangeA QtyChangeT CostChangeT WtPerFt
========================= ================================================== ============================================================================ ============================================================================ ============================================================================ ============================================================================ ============================================================================ ============================================================================ ============================================================================ ============================================================================ ==============
1100SM19050T2C1 1100-H19 LAMI SHIM .050" TYPE 2, CLASS 1 58.2400 890.00 0.0000 0.00 0.0000 0.00 0.0000 0.00 0.000000
1100SM19050T2C1 1100-H19 LAMI SHIM .050" TYPE 2, CLASS 1 0.0000 0.00 58.2400 890.00 0.0000 0.00 0.0000 0.00 0.000000
1100SM19085T2C1 1100-H19 LAMI SHIM .085" TYPE 2, CLASS 1 0.0000 0.00 0.0000 0.00 0.0000 0.00 0.0000 0.00 0.000000
1100SM19085T2C1 1100-H19 LAMI SHIM .085" TYPE 2, CLASS 1 19.8080 208.00 0.0000 0.00 0.0000 0.00 0.0000 0.00 0.000000
1100SM19085T2C1 1100-H19 LAMI SHIM .085" TYPE 2, CLASS 1 0.0000 0.00 19.8080 208.00 0.0000 0.00 0.0000 0.00 0.000000
任何幫助是極大的讚賞。謝謝!!
非常感謝您!我點擊「發佈」按鈕,然後立即看到問題所在。 –